From patchwork Wed Apr 11 03:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10334815 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 A3D0D6053C for ; Wed, 11 Apr 2018 03:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B31122230 for ; Wed, 11 Apr 2018 03:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 900C428674; Wed, 11 Apr 2018 03:43:52 +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 1545322230 for ; Wed, 11 Apr 2018 03:43:52 +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=JfJ3/t5roTm7h/PTo1kaZIvX5QHmOHI7PRIsvxn+MWk=; b=WMZ/XO6zVeoWsJ xGDKMWF7Y14xQ2rb1b40r6E0+h79ZerDDP6xYLlufX3PjBUsY6voUoPsW9J4nwNwXzdQc9H6EgErI LQBh69Qmcxa7mo/CNJwrQC7OYk8sA5Y4IUd95SDYdGI+7V76ROfyXJvNmmFhk59BQL1WPmfeCI075 AnHcshd+5o1k/VwnqvqgoBRtpQGx1cZAKIcwoo/8EpTQagW75X9mLaUqpIycKaYuMCGZ41RZK7uS0 7CCOrglMgU06hZx8POSOd6gMvqh91CR4Vzg6wMWETrateShMAvxdNl+RNv52DSCKggol2bh2UoXR6 6HAkysMgnzE2XRdGcjvQ==; 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 1f66fh-0002gm-WF; Wed, 11 Apr 2018 03:43:46 +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-0001vB-Va; Wed, 11 Apr 2018 03:42:32 +0000 X-UUID: 6169b246de6c465180b80a3ecadd8689-20180411 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 430214460; Wed, 11 Apr 2018 11:42:13 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 11 Apr 2018 11:42:11 +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:11 +0800 From: Xiaolei Li To: , Subject: [PATCH 3/8] mtd: rawnand: mtk: Add DT property mtk,fdm-ecc-size Date: Wed, 11 Apr 2018 11:41:53 +0800 Message-ID: <1523418118-57686-4-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_298705_E339307C X-CRM114-Status: GOOD ( 13.90 ) 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 For some MTK NAND chips, BootROM may access more than one byte ECC protected FDM data, but now we fix ECC protected FDM byte as 1. This will make some chips be failed to boot up. With this DT property setting, different MTK NAND chips with the same NAND controller IP can work well. Signed-off-by: Xiaolei Li --- Documentation/devicetree/bindings/mtd/mtk-nand.txt | 6 ++++++ drivers/mtd/nand/raw/mtk_nand.c | 25 ++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/mtk-nand.txt b/Documentation/devicetree/bindings/mtd/mtk-nand.txt index ef786568..a8e4136 100644 --- a/Documentation/devicetree/bindings/mtd/mtk-nand.txt +++ b/Documentation/devicetree/bindings/mtd/mtk-nand.txt @@ -47,6 +47,12 @@ Children nodes properties: - reg: Chip Select Signal, default 0. Set as reg = <0>, <1> when need 2 CS. Optional: +- mtk,fdm-ecc-size: Integer representing ECC protected FDM bytes. + Should be in the range [1,8], if not present 1. + On some MTK NAND chips, BootROM may access more than + one byte ECC protected FDM data. Different MTK chips + with the same NAND controller IP will work well with + this properity setting. - nand-on-flash-bbt: Store BBT on NAND Flash. - nand-ecc-mode: the NAND ecc mode (check driver for supported modes) - nand-ecc-step-size: Number of data bytes covered by a single ECC step. diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index 6977da3..b05f619 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -86,7 +86,6 @@ #define NFI_FDML(x) (0xA0 + (x) * sizeof(u32) * 2) #define NFI_FDMM(x) (0xA4 + (x) * sizeof(u32) * 2) #define NFI_FDM_MAX_SIZE (8) -#define NFI_FDM_MIN_SIZE (1) #define NFI_MASTER_STA (0x224) #define MASTER_STA_MASK (0x0FFF) #define NFI_EMPTY_THRESH (0x23C) @@ -1118,7 +1117,7 @@ static int mtk_nfc_ooblayout_ecc(struct mtd_info *mtd, int section, .ecc = mtk_nfc_ooblayout_ecc, }; -static void mtk_nfc_set_fdm(struct mtk_nfc_fdm *fdm, struct mtd_info *mtd) +static int mtk_nfc_set_fdm(struct mtk_nfc_fdm *fdm, struct mtd_info *mtd) { struct nand_chip *nand = mtd_to_nand(mtd); struct mtk_nfc_nand_chip *chip = to_mtk_nand(nand); @@ -1129,11 +1128,15 @@ static void mtk_nfc_set_fdm(struct mtk_nfc_fdm *fdm, struct mtd_info *mtd) mtk_ecc_get_parity_bits(nfc->ecc), 8); fdm->reg_size = chip->spare_per_sector - ecc_bytes; - if (fdm->reg_size > NFI_FDM_MAX_SIZE) + if (fdm->reg_size > NFI_FDM_MAX_SIZE) { fdm->reg_size = NFI_FDM_MAX_SIZE; + } else if (fdm->reg_size < fdm->ecc_size) { + dev_err(nfc->dev, "fdm reg size(%u) is less than fdm ecc size(%u)\n", + fdm->reg_size, fdm->ecc_size); + return -ENOTSUPP; + } - /* bad block mark storage */ - fdm->ecc_size = 1; + return 0; } static void mtk_nfc_set_bad_mark_ctl(struct mtk_nfc_bad_mark_ctl *bm_ctl, @@ -1185,6 +1188,7 @@ static int mtk_nfc_set_spare_per_sector(u32 *sps, struct mtd_info *mtd) static int mtk_nfc_ecc_init(struct device *dev, struct mtd_info *mtd) { struct nand_chip *nand = mtd_to_nand(mtd); + struct mtk_nfc_nand_chip *mtk_nand = to_mtk_nand(nand); struct mtk_nfc *nfc = nand_get_controller_data(nand); u32 spare; int free, ret; @@ -1236,7 +1240,7 @@ static int mtk_nfc_ecc_init(struct device *dev, struct mtd_info *mtd) nand->ecc.strength = (spare << 3) / mtk_ecc_get_parity_bits(nfc->ecc); } else if (free < 0) { - spare -= NFI_FDM_MIN_SIZE; + spare -= mtk_nand->fdm.ecc_size; nand->ecc.strength = (spare << 3) / mtk_ecc_get_parity_bits(nfc->ecc); } @@ -1285,6 +1289,10 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, chip->sels[i] = tmp; } + /* If not present, set 1 for bad block mark storage */ + if (of_property_read_u32(np, "mtk,fdm-ecc-size", &chip->fdm.ecc_size)) + chip->fdm.ecc_size = 1; + nand = &chip->nand; nand->controller = &nfc->controller; @@ -1345,7 +1353,10 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, if (ret) return ret; - mtk_nfc_set_fdm(&chip->fdm, mtd); + ret = mtk_nfc_set_fdm(&chip->fdm, mtd); + if (ret) + return ret; + mtk_nfc_set_bad_mark_ctl(&chip->bad_mark, mtd); len = mtd->writesize + mtd->oobsize;