From patchwork Wed Apr 11 03:41:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10334811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F84D60365 for ; Wed, 11 Apr 2018 03:42:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376A9205F6 for ; Wed, 11 Apr 2018 03:42:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C26222230; Wed, 11 Apr 2018 03:42:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C878B205F6 for ; Wed, 11 Apr 2018 03:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FJTjC2SFbcepbGeTQg0seRPMxo9LicuI5g0p8CK1V1k=; b=AG4o0qz4On1eWF Eusb2AzRBb665ktbeMyuWeVJRh9PHNYk3MkbpOGaIjudbzw0XKSwGgUSBko1so8D4sgzG+Xbx1G7s gFUYk10/XnKK/b4r4h33tqM6MeSoTG6GK/zfhMoTgEBH8zQVFg6I+TOPrp8fOhG8F5vHCIABgrjhz /yOKHHJmJY6KcKKJM6P0JgApOCI6MEVm5In3X8RZ9vz5qsXkFuzdg9U0F3yW3X2xfwmqnd3koaLR6 OtniW3PfSDSbnbLxfxZbeG43eu3/8PfJCFiMQWQVgikXKLvWwBfDE5EXR3NddYFbEcX7a7Ccc/weq 6ViuPbjYOulwEeOFxgIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f66eY-0001yr-16; Wed, 11 Apr 2018 03:42:34 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f66eS-0001v8-Va; Wed, 11 Apr 2018 03:42:30 +0000 X-UUID: ed3155e4496046df961c56379c6ac172-20180411 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1724292101; Wed, 11 Apr 2018 11:42:15 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 11 Apr 2018 11:42:14 +0800 Received: from mtkslt306.mediatek.inc (10.21.14.136) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Wed, 11 Apr 2018 11:42:13 +0800 From: Xiaolei Li To: , Subject: [PATCH 6/8] mtd: rawnand: mtk: Introduce mtk_ecc_calc_parity_bytes() function Date: Wed, 11 Apr 2018 11:41:56 +0800 Message-ID: <1523418118-57686-7-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523418118-57686-1-git-send-email-xiaolei.li@mediatek.com> References: <1523418118-57686-1-git-send-email-xiaolei.li@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_204229_155951_C5E85026 X-CRM114-Status: GOOD ( 10.12 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, xiaolei.li@mediatek.com, linux-mtd@lists.infradead.org, srv_heupstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce mtk_ecc_calc_parity_bytes() function to calculate ECC parity byte number. Signed-off-by: Xiaolei Li --- drivers/mtd/nand/raw/mtk_ecc.c | 10 ++++++++-- drivers/mtd/nand/raw/mtk_ecc.h | 1 + drivers/mtd/nand/raw/mtk_nand.c | 6 ++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/mtk_ecc.c b/drivers/mtd/nand/raw/mtk_ecc.c index 40d86a8..717d553 100644 --- a/drivers/mtd/nand/raw/mtk_ecc.c +++ b/drivers/mtd/nand/raw/mtk_ecc.c @@ -408,7 +408,7 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config, mtk_ecc_wait_idle(ecc, ECC_ENCODE); /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */ - len = (config->strength * ecc->caps->parity_bits + 7) >> 3; + len = mtk_ecc_calc_parity_bytes(ecc, config->strength); /* write the parity bytes generated by the ECC back to temp buffer */ __ioread32_copy(ecc->eccdata, @@ -451,6 +451,12 @@ unsigned int mtk_ecc_get_parity_bits(struct mtk_ecc *ecc) } EXPORT_SYMBOL(mtk_ecc_get_parity_bits); +int mtk_ecc_calc_parity_bytes(struct mtk_ecc *ecc, int ecc_strength) +{ + return DIV_ROUND_UP(ecc->caps->parity_bits * ecc_strength, 8); +} +EXPORT_SYMBOL(mtk_ecc_calc_parity_bytes); + static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = { .err_mask = 0x3f, .ecc_strength = ecc_strength_mt2701, @@ -516,7 +522,7 @@ static int mtk_ecc_probe(struct platform_device *pdev) max_eccdata_size = ecc->caps->num_ecc_strength - 1; max_eccdata_size = ecc->caps->ecc_strength[max_eccdata_size]; - max_eccdata_size = (max_eccdata_size * ecc->caps->parity_bits + 7) >> 3; + max_eccdata_size = mtk_ecc_calc_parity_bytes(ecc, max_eccdata_size); max_eccdata_size = round_up(max_eccdata_size, 4); ecc->eccdata = devm_kzalloc(dev, max_eccdata_size, GFP_KERNEL); if (!ecc->eccdata) diff --git a/drivers/mtd/nand/raw/mtk_ecc.h b/drivers/mtd/nand/raw/mtk_ecc.h index a455df0..c1546f9 100644 --- a/drivers/mtd/nand/raw/mtk_ecc.h +++ b/drivers/mtd/nand/raw/mtk_ecc.h @@ -42,6 +42,7 @@ struct mtk_ecc_config { void mtk_ecc_disable(struct mtk_ecc *); void mtk_ecc_adjust_strength(struct mtk_ecc *ecc, u32 *p); unsigned int mtk_ecc_get_parity_bits(struct mtk_ecc *ecc); +int mtk_ecc_calc_parity_bytes(struct mtk_ecc *ecc, int ecc_strength); struct mtk_ecc *of_mtk_ecc_get(struct device_node *); void mtk_ecc_release(struct mtk_ecc *); diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index 2c244c2..249b3fb 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -1143,8 +1143,7 @@ static int mtk_nfc_set_fdm(struct mtk_nfc_fdm *fdm, struct mtd_info *mtd) struct mtk_nfc *nfc = nand_get_controller_data(nand); u32 ecc_bytes; - ecc_bytes = DIV_ROUND_UP(nand->ecc.strength * - mtk_ecc_get_parity_bits(nfc->ecc), 8); + ecc_bytes = mtk_ecc_calc_parity_bytes(nfc->ecc, nand->ecc.strength); fdm->reg_size = chip->spare_per_sector - ecc_bytes; if (fdm->reg_size > NFI_FDM_MAX_SIZE) { @@ -1245,8 +1244,7 @@ static int mtk_nfc_ecc_init(struct device *dev, struct mtd_info *mtd) return ret; /* calculate oob bytes except ecc parity data */ - free = (nand->ecc.strength * mtk_ecc_get_parity_bits(nfc->ecc) - + 7) >> 3; + free = mtk_ecc_calc_parity_bytes(nfc->ecc, nand->ecc.strength); free = spare - free; /*