From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from s250.sam-solutions.net ([217.21.49.219]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WMyj3-00033i-D8 for barebox@lists.infradead.org; Mon, 10 Mar 2014 11:50:35 +0000 Received: from s246.sam-solutions.net ([217.21.35.55]) by s250.sam-solutions.net with esmtps (TLSv1:RC4-MD5:128) (Exim 4.77) (envelope-from ) id 1WMyij-00037D-16 for barebox@lists.infradead.org; Mon, 10 Mar 2014 14:50:13 +0300 From: Dmitry Lavnikevich Date: Mon, 10 Mar 2014 14:39:53 +0300 Message-ID: <1394451593-3090-5-git-send-email-d.lavnikevich@sam-solutions.com> In-Reply-To: <1394451593-3090-1-git-send-email-d.lavnikevich@sam-solutions.com> References: <1394451593-3090-1-git-send-email-d.lavnikevich@sam-solutions.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 5/5] nand: mxs: Fix for calculating ecc strength on some types of NAND flash To: barebox@lists.infradead.org Cc: Grigory Milev , Dmitry Lavnikevich 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 Signed-off-by: Grigory Milev --- 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.9.0 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox