u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>,
	Michael Nazzareno Trimarchi <michael@amarulasolutions.com>,
	William Zhang <william.zhang@broadcom.com>
Cc: "Anand Gore" <anand.gore@broadcom.com>,
	"Kursad Oney" <kursad.oney@broadcom.com>,
	"Joel Peshkin" <joel.peshkin@broadcom.com>,
	"Philippe Reynes" <philippe.reynes@softathome.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Linus Walleij" <linus.walleij@linaro.org>
Subject: [PATCH v4 2/5] mtd: rawnand: nand_base: Handle algorithm selection
Date: Fri,  7 Apr 2023 15:40:05 +0200	[thread overview]
Message-ID: <20230407134008.1939717-3-linus.walleij@linaro.org> (raw)
In-Reply-To: <20230407134008.1939717-1-linus.walleij@linaro.org>

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.

Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
Acked-by: William Zhang <william.zhang@broadcom.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v3->v4:
- After a bug report from Tom, be more careful when
  assigning algorithm: only overwrite the chip default when
  something other than undefined was actually detected.
ChangeLog v2->v3:
- Collect review tags from Michael and William
- Resend with the NorthStar enablement patches
ChangeLog v1->v2:
- Drop pointless check for ecc_algo >= 0, it is always
  >= 0.
---
 drivers/mtd/nand/raw/nand_base.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 9eba360d55f3..6b4adcf6bdc9 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,22 @@ 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"))
-			ecc_mode = NAND_ECC_SOFT_BCH;
+	str = ofnode_read_string(node, "nand-ecc-algo");
+	if (str) {
+		/*
+		 * If we are in NAND_ECC_SOFT mode, just alter the
+		 * soft mode to BCH here. No change of algorithm.
+		 */
+		if (ecc_mode == NAND_ECC_SOFT) {
+			if (!strcmp(str, "bch"))
+				ecc_mode = NAND_ECC_SOFT_BCH;
+		} else {
+			if (!strcmp(str, "bch")) {
+				ecc_algo = NAND_ECC_BCH;
+			} else if (!strcmp(str, "hamming")) {
+				ecc_algo = NAND_ECC_HAMMING;
+			}
+		}
 	}
 
 	ecc_strength = ofnode_read_s32_default(node,
@@ -4529,6 +4542,14 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
 		return -EINVAL;
 	}
 
+	/*
+	 * Chip drivers may have assigned default algorithms here,
+	 * onlt override it if we have found something explicitly
+	 * specified in the device tree.
+	 */
+	if (ecc_algo != NAND_ECC_UNKNOWN)
+		chip->ecc.algo = ecc_algo;
+
 	if (ecc_mode >= 0)
 		chip->ecc.mode = ecc_mode;
 
-- 
2.39.2


  parent reply	other threads:[~2023-04-07 13:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 13:40 [PATCH v4 0/5] Add Broadcom Northstar basic support Linus Walleij
2023-04-07 13:40 ` [PATCH v4 1/5] nand: brcmnand: add iproc support Linus Walleij
2023-04-07 13:40 ` Linus Walleij [this message]
2023-04-07 17:46   ` [PATCH v4 2/5] mtd: rawnand: nand_base: Handle algorithm selection Tom Rini
2023-04-07 13:40 ` [PATCH v4 3/5] arm: dts: Import device tree for Broadcom Northstar Linus Walleij
2023-04-07 17:46   ` Tom Rini
2023-04-07 21:28     ` Linus Walleij
2023-04-07 21:39       ` Tom Rini
2023-04-07 13:40 ` [PATCH v4 4/5] arm: Add support for the Broadcom Northstar SoCs Linus Walleij
2023-04-07 13:40 ` [PATCH v4 5/5] board: Add new Broadcom Northstar board Linus Walleij
2023-04-07 17:46   ` Tom Rini
2023-04-07 21:31     ` Linus Walleij
2023-04-07 21:40       ` Tom Rini
2023-04-08 22:03         ` Linus Walleij
2023-04-13  7:49 ` [PATCH v4 0/5] Add Broadcom Northstar basic support Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230407134008.1939717-3-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=anand.gore@broadcom.com \
    --cc=joel.peshkin@broadcom.com \
    --cc=kursad.oney@broadcom.com \
    --cc=michael@amarulasolutions.com \
    --cc=philippe.reynes@softathome.com \
    --cc=rafal@milecki.pl \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=william.zhang@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).