From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753568AbbIAQ4N (ORCPT ); Tue, 1 Sep 2015 12:56:13 -0400 Received: from mail.kmu-office.ch ([178.209.48.109]:43344 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753308AbbIAQ4L (ORCPT ); Tue, 1 Sep 2015 12:56:11 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Tue, 01 Sep 2015 09:55:48 -0700 From: Stefan Agner To: computersforpeace@gmail.com Cc: sebastian@breakpoint.cc, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, shawn.guo@linaro.org, kernel@pengutronix.de, boris.brezillon@free-electrons.com, marb@ixxat.de, aaron@tastycactus.com, bpringlemeir@gmail.com, linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, albert.aribaud@3adev.fr, klimov.linux@gmail.com, Bill Pringlemeir Subject: Re: [PATCH v11 2/5] mtd: nand: vf610_nfc: add hardware BCH-ECC support In-Reply-To: <1440722100-25388-3-git-send-email-stefan@agner.ch> References: <1440722100-25388-1-git-send-email-stefan@agner.ch> <1440722100-25388-3-git-send-email-stefan@agner.ch> Message-ID: <575f176ee9d5e6d785ed2352887d5336@agner.ch> User-Agent: Roundcube Webmail/1.1.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2015-08-27 17:34, Stefan Agner wrote: > +static inline int vf610_nfc_correct_data(struct mtd_info *mtd, uint8_t *dat, > + uint8_t *oob, int page) > +{ > + struct vf610_nfc *nfc = mtd_to_nfc(mtd); > + u32 ecc_status_off = NFC_MAIN_AREA(0) + ECC_SRAM_ADDR + ECC_STATUS; > + u8 ecc_status; > + u8 ecc_count; > + int flips; > + int flips_threshold = nfc->chip.ecc.strength / 2; > + > + ecc_status = vf610_nfc_read(nfc, ecc_status_off) & 0xff; > + ecc_count = ecc_status & ECC_STATUS_ERR_COUNT; > + > + if (!(ecc_status & ECC_STATUS_MASK)) > + return ecc_count; > + > + /* Read OOB without ECC unit enabled */ > + vf610_nfc_command(mtd, NAND_CMD_READOOB, 0, page); > + vf610_nfc_read_buf(mtd, oob, mtd->oobsize); > + > + /* > + * On an erased page, bit count (including OOB) should be zero or > + * at least less then half of the ECC strength. > + */ > + flips = count_written_bits(dat, nfc->chip.ecc.size, flips_threshold); > + flips += count_written_bits(oob, mtd->oobsize, flips_threshold); > + > + if (unlikely(flips > flips_threshold)) > + return -EINVAL; > + > + /* Erased page. */ > + memset(dat, 0xff, nfc->chip.ecc.size); > + memset(oob, 0xff, mtd->oobsize); > + return 0; I guess I should return the amount of bitflips here. Will send out a v12 today. -- Stefan