From: Michael Grzeschik <grzeschik@puzzle.ch>
To: Sascha Hauer <s.hauer@pengutronix.de>,
"open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Michael Grzeschik <grzeschik@puzzle.ch>
Subject: [PATCH 2/6] mtd: nand: orion: set Hamming ECC algorithm in ->attach_chip()
Date: Tue, 03 Nov 2026 22:31:08 +0100 [thread overview]
Message-ID: <20261103-orion_kw_mvebu-v1-2-86442c0d283e@puzzle.ch> (raw)
In-Reply-To: <20261103-orion_kw_mvebu-v1-0-86442c0d283e@puzzle.ch>
The driver selects software Hamming ECC before nand_scan(), but
rawnand_dt_init() unconditionally overwrites chip->ecc.algo with the
device tree setting. None of the Kirkwood device trees has an ECC
property, so the algorithm ends up as NAND_ECC_ALGO_UNKNOWN and probing
fails:
WARNING: at drivers/mtd/nand/raw/nand_base.c:5783/nand_set_ecc_soft_ops()!
WARNING: Unsupported ECC algorithm!
leaving all boards with an orion NAND controller without NAND.
Do the same as the Linux orion_nand driver: keep the software engine as
default before scanning, and pick the Hamming algorithm in
->attach_chip(), which runs after the device tree has been parsed, if
neither the device tree nor anything else chose one.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Grzeschik <grzeschik@puzzle.ch>
---
drivers/mtd/nand/raw/nand_orion.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/raw/nand_orion.c b/drivers/mtd/nand/raw/nand_orion.c
index c7fa4a08e9..68797b9b38 100644
--- a/drivers/mtd/nand/raw/nand_orion.c
+++ b/drivers/mtd/nand/raw/nand_orion.c
@@ -73,6 +73,19 @@ static void orion_nand_read_buf(struct nand_chip *chip, uint8_t *buf, int len)
buf[i++] = readb(io_base);
}
+static int orion_nand_attach_chip(struct nand_chip *chip)
+{
+ if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT &&
+ chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN)
+ chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
+
+ return 0;
+}
+
+static const struct nand_controller_ops orion_nand_controller_ops = {
+ .attach_chip = orion_nand_attach_chip,
+};
+
static int orion_nand_probe(struct device *dev)
{
struct resource *iores;
@@ -117,8 +130,13 @@ static int orion_nand_probe(struct device *dev)
chip->legacy.IO_ADDR_R = chip->legacy.IO_ADDR_W = io_base;
chip->legacy.cmd_ctrl = orion_nand_cmd_ctrl;
chip->legacy.read_buf = orion_nand_read_buf;
+ /*
+ * The default ECC engine is software. The algorithm is set in
+ * ->attach_chip(), after rawnand_dt_init() has overwritten it with the
+ * (usually absent) device tree setting.
+ */
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
- chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
+ chip->legacy.dummy_controller.ops = &orion_nand_controller_ops;
WARN(width > 16, "%d bit bus width out of range", width);
if (width == 16)
--
2.53.0
next prev parent reply other threads:[~2026-11-03 21:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 21:31 [PATCH 0/6] orion/kw/mvebu: stability/usability patches Michael Grzeschik
2026-11-03 21:31 ` [PATCH 1/6] images: mvebu: skip images whose binary header is missing Michael Grzeschik
2026-11-03 21:31 ` Michael Grzeschik [this message]
2026-11-03 21:31 ` [PATCH 3/6] gpio: orion: do not let banks without alias collide Michael Grzeschik
2026-11-03 21:31 ` [PATCH 4/6] filetype: detect kwbimage v0 images for NAND boot Michael Grzeschik
2026-11-03 21:31 ` [PATCH 5/6] mtd: nand: orion: register the NAND device as "nand" Michael Grzeschik
2026-11-03 21:31 ` [PATCH 6/6] gpio: orion: register at coredevice level Michael Grzeschik
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=20261103-orion_kw_mvebu-v1-2-86442c0d283e@puzzle.ch \
--to=grzeschik@puzzle.ch \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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