From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de
Subject: [PATCH 1/2] mtd: nand: mxs: add helper to calculate the page size
Date: Fri, 26 Jul 2019 11:33:59 +0200 [thread overview]
Message-ID: <20190726093400.4957-1-m.felsch@pengutronix.de> (raw)
Since commit 51061a9884a3 ("mtd: nand: nand_mxs: Add subpage read
support") the ecc_read_page and ecc_write_page page_size can be differ.
Because during ecc_read_page the page_size() is based on the ecc
calculation. Unlike to the ecc_write_page() which uses the nand
writesize and oobsize information.
This commit factor out the page size calculation during ecc_read_page to
a helper function. So we can reuse it during ecc_write_page().
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/mtd/nand/nand_mxs.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index c3b07aa3f6..762c751fa7 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -688,6 +688,25 @@ static uint8_t mxs_nand_read_byte(struct mtd_info *mtd)
return buf;
}
+/*
+ * Determine the page size including user data + ecc data
+ */
+static unsigned int mxs_nand_get_page_size(struct mtd_info *mtd,
+ unsigned int bytes)
+{
+ unsigned int eccstrength, nchunks, pagesize;
+
+ eccstrength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
+
+ bytes = roundup(bytes, MXS_NAND_CHUNK_DATA_CHUNK_SIZE);
+ nchunks = mxs_nand_ecc_chunk_cnt(bytes);
+ pagesize = MXS_NAND_METADATA_SIZE;
+ pagesize += MXS_NAND_CHUNK_DATA_CHUNK_SIZE * nchunks;
+ pagesize += DIV_ROUND_UP(13 * eccstrength * nchunks, 8);
+
+ return pagesize;
+}
+
static void mxs_nand_config_bch(struct mtd_info *mtd, int readlen)
{
struct nand_chip *nand = mtd->priv;
@@ -728,15 +747,11 @@ static int __mxs_nand_ecc_read_page(struct mtd_info *mtd, struct nand_chip *nand
uint32_t corrected = 0, failed = 0;
uint8_t *status;
unsigned int max_bitflips = 0;
- int i, ret, readtotal, nchunks, eccstrength;
-
- eccstrength = mxs_nand_get_ecc_strength(mtd->writesize, mtd->oobsize);
+ int i, ret, readtotal, nchunks;
readlen = roundup(readlen, MXS_NAND_CHUNK_DATA_CHUNK_SIZE);
nchunks = mxs_nand_ecc_chunk_cnt(readlen);
- readtotal = MXS_NAND_METADATA_SIZE;
- readtotal += MXS_NAND_CHUNK_DATA_CHUNK_SIZE * nchunks;
- readtotal += DIV_ROUND_UP(13 * eccstrength * nchunks, 8);
+ readtotal = mxs_nand_get_page_size(mtd, readlen);
mxs_nand_config_bch(mtd, readtotal);
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2019-07-26 9:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-26 9:33 Marco Felsch [this message]
2019-07-26 9:34 ` [PATCH 2/2] mtd: nand: mxs: sync page_size information Marco Felsch
2019-08-05 10:17 ` Sascha Hauer
2019-08-08 13:03 ` Marco Felsch
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=20190726093400.4957-1-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=mfe@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