All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder@fris.de>
To: u-boot@lists.denx.de
Cc: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
	Frieder Schrempf <frieder.schrempf@kontron.de>,
	Simon Glass <sjg@chromium.org>, Stefan Roese <sr@denx.de>
Subject: [PATCH 2/5] mtd/spinand: sync core spinand code with linux-5.10.118
Date: Tue, 10 Jan 2023 12:58:39 +0100	[thread overview]
Message-ID: <20230110115843.391630-2-frieder@fris.de> (raw)
In-Reply-To: <20230110115843.391630-1-frieder@fris.de>

From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>

This brings us closer to the current Linux kernel implementation of
the spinand core and makes backporting features and fixes easier.

This does not include the latest kernel implementation as this would
require a substantial amount of extra work due to the missing
ECC engine abstraction layer in U-Boot.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de> (add commit message)
---
 drivers/mtd/nand/spi/core.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index d92de9c24e3..886e66e7847 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -326,6 +326,13 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
 	u16 column = 0;
 	int ret;
 
+	/*
+	 * Looks like PROGRAM LOAD (AKA write cache) does not necessarily reset
+	 * the cache content to 0xFF (depends on vendor implementation), so we
+	 * must fill the page cache entirely even if we only want to program
+	 * the data portion of the page, otherwise we might corrupt the BBM or
+	 * user data previously programmed in OOB area.
+	 */
 	memset(spinand->databuf, 0xff,
 	       nanddev_page_size(nand) +
 	       nanddev_per_page_oobsize(nand));
@@ -598,12 +605,12 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
 		if (ret == -EBADMSG) {
 			ecc_failed = true;
 			mtd->ecc_stats.failed++;
-			ret = 0;
 		} else {
 			mtd->ecc_stats.corrected += ret;
 			max_bitflips = max_t(unsigned int, max_bitflips, ret);
 		}
 
+		ret = 0;
 		ops->retlen += iter.req.datalen;
 		ops->oobretlen += iter.req.ooblen;
 	}
@@ -669,16 +676,9 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos)
 		.oobbuf.in = marker,
 		.mode = MTD_OPS_RAW,
 	};
-	int ret;
-
-	ret = spinand_select_target(spinand, pos->target);
-	if (ret)
-		return ret;
-
-	ret = spinand_read_page(spinand, &req, false);
-	if (ret)
-		return ret;
 
+	spinand_select_target(spinand, pos->target);
+	spinand_read_page(spinand, &req, false);
 	if (marker[0] != 0xff || marker[1] != 0xff)
 		return true;
 
@@ -722,6 +722,10 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
 	if (ret)
 		return ret;
 
+	ret = spinand_write_enable_op(spinand);
+	if (ret)
+		return ret;
+
 	return spinand_write_page(spinand, &req);
 }
 
-- 
2.39.0


  reply	other threads:[~2023-01-10 11:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 11:58 [PATCH 1/5] mtd/spinand: rework detect procedure for different READ_ID operation Frieder Schrempf
2023-01-10 11:58 ` Frieder Schrempf [this message]
2023-01-10 11:58 ` [PATCH 3/5] mtd/spinand: sync supported devices with linux-5.15.43 Frieder Schrempf
2023-01-10 11:58 ` [PATCH 4/5] mtd: spinand: winbond: fix flash identification Frieder Schrempf
2023-01-10 11:58 ` [PATCH 5/5] mtd: spinand: winbond: add Winbond W25N02KV flash support Frieder Schrempf
2023-02-09  9:24 ` [PATCH 1/5] mtd/spinand: rework detect procedure for different READ_ID operation Frieder Schrempf
2023-02-09 16:52   ` Tom Rini
2023-02-10 11:57     ` Michael Nazzareno Trimarchi
2023-02-13  9:51       ` Frieder Schrempf
2023-03-28  7:57       ` Frieder Schrempf
2023-04-18 13:46         ` Frieder Schrempf
2023-04-18 13:48           ` Michael Nazzareno Trimarchi
2023-04-18 18:19             ` Mikhail Kshevetskiy
2023-04-18 18:24               ` Michael Nazzareno Trimarchi
2023-04-19  7:08                 ` Frieder Schrempf
2023-05-09  7:09           ` Frieder Schrempf
2023-05-15 21:12             ` Tom Rini
2023-05-15 21:33               ` Michael Nazzareno Trimarchi
2023-05-17  7:43                 ` Frieder Schrempf
2023-05-31 10:58                   ` Frieder Schrempf
2023-05-31 12:58                     ` Dario Binacchi
2023-05-31 13:02                       ` Frieder Schrempf

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=20230110115843.391630-2-frieder@fris.de \
    --to=frieder@fris.de \
    --cc=frieder.schrempf@kontron.de \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.