mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.net>
To: barebox@lists.infradead.org
Cc: Grigory Milev <G.Milev@sam-solutions.com>,
	Dmitry Lavnikevich <D.Lavnikevich@sam-solutions.com>
Subject: [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash
Date: Fri, 7 Mar 2014 14:15:22 +0300	[thread overview]
Message-ID: <5319AA4A.2020704@sam-solutions.net> (raw)
In-Reply-To: <1394190783-12978-1-git-send-email-d.lavnikevich@sam-solutions.com>

Was tested on NAND with {writesize=4096, oobsize=224} and
{writesize=2048, oobsize=64}.

This patch will not break any NAND that was working
before. Implemented calculation way may be used for other NAND chips
with writesize == 2048 but oobsize != 64.

Signed-off-by: Dmitry Lavnikevich <d.lavnikevich@sam-solutions.com>
Signed-off-by: Grigory Milev <g.milev@sam-solutions.com>
---
  drivers/mtd/nand/nand_mxs.c | 21 +++++++++++++++++----
  1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 237a423..b06b558 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -234,18 +234,31 @@ static uint32_t mxs_nand_aux_status_offset(void)
  static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
  						uint32_t page_oob_size)
  {
+	int ecc_chunk_count = mxs_nand_ecc_chunk_cnt(page_data_size);
+	int ecc_strength = 0;
+	int gf_len = 13;  /* length of Galois Field for non-DDR nand */
+
+	/*
+	 * Possibly this if-else calculation may be removed since
+	 * ecc_strength calculated after it is taken from kernel driver
+	 * and therefore should work for all cases. But it was tested only
+	 * on devices with {data_size = 2046, oob_size = 64} and
+	 * {data_size = 4096, oob_size = 224} configuration.
+	 */
  	if (page_data_size == 2048)
  		return 8;
-
-	if (page_data_size == 4096) {
+	else if (page_data_size == 4096) {
  		if (page_oob_size == 128)
  			return 8;
-
  		if (page_oob_size == 218)
  			return 16;
  	}
  -	return 0;
+	ecc_strength = ((page_oob_size - MXS_NAND_METADATA_SIZE) * 8)
+		/ (gf_len * ecc_chunk_count);
+
+	/* We need the minor even number. */
+	return rounddown(ecc_strength, 2);
  }
   static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
-- 
1.8.5.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-03-07 11:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1394190783-12978-1-git-send-email-d.lavnikevich@sam-solutions.com>
2014-03-07 11:14 ` [PATCH 2/5] mtd: Support for 4GB partitions Dmitry Lavnikevich
2014-03-07 11:15 ` [PATCH 3/5] ubi: Fix for creating ubi volumes with 64bit size Dmitry Lavnikevich
2014-03-07 11:15 ` [PATCH 4/5] nand: mxs: Check for up to 4 NAND chips Dmitry Lavnikevich
2014-03-07 11:15 ` Dmitry Lavnikevich [this message]
2014-03-10 11:39 [PATCH 1/5] mtd: Update internal API to support 64-bit device size Dmitry Lavnikevich
2014-03-10 11:39 ` [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash Dmitry Lavnikevich

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=5319AA4A.2020704@sam-solutions.net \
    --to=d.lavnikevich@sam-solutions.net \
    --cc=D.Lavnikevich@sam-solutions.com \
    --cc=G.Milev@sam-solutions.com \
    --cc=barebox@lists.infradead.org \
    /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