From: Bean Huo <huobean@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com,
s.hauer@pengutronix.de, boris.brezillon@collabora.com,
derosier@gmail.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
huobean@gmail.com, Bean Huo <beanhuo@micron.com>
Subject: [PATCH v6 4/5] mtd: rawnand: Introduce a new function nand_check_is_erased_page()
Date: Mon, 25 May 2020 14:18:12 +0200 [thread overview]
Message-ID: <20200525121814.31934-5-huobean@gmail.com> (raw)
In-Reply-To: <20200525121814.31934-1-huobean@gmail.com>
From: Bean Huo <beanhuo@micron.com>
Add a new function nand_check_is_erased_page() in nand_base.c, which is
used to check whether one programmable page is empty or already programmed.
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
drivers/mtd/nand/raw/nand_base.c | 40 ++++++++++++++++++++++++++++++++
include/linux/mtd/rawnand.h | 2 ++
2 files changed, 42 insertions(+)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index ab39bb33e688..05ee32106af9 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -2697,6 +2697,46 @@ int nand_check_erased_ecc_chunk(void *data, int datalen,
}
EXPORT_SYMBOL(nand_check_erased_ecc_chunk);
+/**
+ * nand_check_is_erased_page - check if this page is a empty page
+ * @chip: nand chip info structure
+ * @page_data: data buffer containing the data in the page being checked
+ * @oob: indicate if chip->oob_poi points to oob date of the page
+ *
+ * Returns true if this is an un-programmed page, false otherwise.
+ */
+int nand_check_is_erased_page(struct nand_chip *chip, u8 *page_data, bool oob)
+{
+ struct mtd_info *mtd = nand_to_mtd(chip);
+ int ret, i;
+ u8 *databuf, *eccbuf = NULL;
+ struct mtd_oob_region oobregion;
+ int datasize, eccbytes = 0;
+
+ databuf = page_data;
+ datasize = chip->ecc.size;
+
+ if (oob) {
+ mtd_ooblayout_ecc(mtd, 0, &oobregion);
+ eccbuf = chip->oob_poi + oobregion.offset;
+ eccbytes = chip->ecc.bytes;
+ }
+
+ for (i = 0; i < chip->ecc.steps; i++) {
+ ret = nand_check_erased_ecc_chunk(databuf, datasize,
+ eccbuf, eccbytes,
+ NULL, 0, chip->ecc.strength);
+ if (ret < 0)
+ return false;
+
+ databuf += chip->ecc.size;
+ eccbuf += chip->ecc.bytes;
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(nand_check_is_erased_page);
+
/**
* nand_read_page_raw_notsupp - dummy read raw page function
* @chip: nand chip info structure
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index ae1cc60260a7..44c2715691bb 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1339,6 +1339,8 @@ int nand_check_erased_ecc_chunk(void *data, int datalen,
void *extraoob, int extraooblen,
int threshold);
+int nand_check_is_erased_page(struct nand_chip *chip, u8 *page_data, bool oob);
+
int nand_ecc_choose_conf(struct nand_chip *chip,
const struct nand_ecc_caps *caps, int oobavail);
--
2.17.1
next prev parent reply other threads:[~2020-05-25 12:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 12:18 [PATCH v6 0/5] Micron SLC NAND filling block Bean Huo
2020-05-25 12:18 ` [PATCH v6 1/5] mtd: rawnand: group all NAND specific ops into new nand_chip_ops Bean Huo
2020-05-25 12:18 ` [PATCH v6 2/5] mtd: rawnand: Add {pre, post}_erase hooks in nand_chip_ops Bean Huo
2020-05-25 12:18 ` [PATCH v6 3/5] mtd: rawnand: Add write_oob hook " Bean Huo
2020-05-25 12:18 ` Bean Huo [this message]
2020-05-25 12:18 ` [PATCH v6 5/5] mtd: rawnand: micron: Micron SLC NAND filling block Bean Huo
2020-05-28 14:14 ` [PATCH v6 0/5] " Bean Huo
2020-06-01 21:10 ` Bean Huo
2020-06-02 7:05 ` Miquel Raynal
2020-06-02 7:48 ` Boris Brezillon
2020-06-02 8:59 ` Bean Huo
2020-06-02 11:53 ` Boris Brezillon
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=20200525121814.31934-5-huobean@gmail.com \
--to=huobean@gmail.com \
--cc=beanhuo@micron.com \
--cc=boris.brezillon@collabora.com \
--cc=derosier@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=s.hauer@pengutronix.de \
--cc=vigneshr@ti.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).