From patchwork Mon Apr 16 07:41:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaolei li X-Patchwork-Id: 10342323 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 BE56F601C2 for ; Mon, 16 Apr 2018 07:42:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF6B627F82 for ; Mon, 16 Apr 2018 07:42:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A43F92838F; Mon, 16 Apr 2018 07: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 4255827F82 for ; Mon, 16 Apr 2018 07:42:40 +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=2UzozsYv/cz/kh0UJnnWCA7AQs12kbDr8ck4cLLVuzc=; b=rAm1Ec8jMqC13n X876E9S8h1IctAl7uyhcqAM0Uo6t/fXDT3e7ucv+j+ODFWACJOMzneGb8CIgQu/7l30zqDSZoD8Jo IZuVhrBvbiXD7JX5NdgEuE3Nryi2sZ91TU8iceeveo0wi7qMkrTozPRFGT9ldLhJ9eQN6Zo21N6AG wJlRIZvK4jMtdCK4xQmnfFaiWcONiXVfJBnU7Do5R6zMqV4rMzWcCifklhlqbmjJfMgUmV+DHhaFN +BiW5jLelkoBReiord1Zi8ZgVlezyzelIrshlqDYCCm9Lc8ZX4y5SWytjWZDM4tvcXFBF2tyyRr+t p6779Eb3jbkRYP4zj7sA==; 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 1f7ymZ-0002bN-SP; Mon, 16 Apr 2018 07:42:35 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f7ylT-0001qT-Ti; Mon, 16 Apr 2018 07:41:31 +0000 X-UUID: 8da4fdf2e7ac44a292200f4f180251be-20180416 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 99153533; Mon, 16 Apr 2018 15:41:10 +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; Mon, 16 Apr 2018 15:41:08 +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; Mon, 16 Apr 2018 15:41:08 +0800 From: Xiaolei Li To: , Subject: [PATCH v2 3/4] mtd: rawnand: mtk: Replace max_sector_size with sector size array Date: Mon, 16 Apr 2018 15:41:03 +0800 Message-ID: <1523864464-41059-4-git-send-email-xiaolei.li@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523864464-41059-1-git-send-email-xiaolei.li@mediatek.com> References: <1523864464-41059-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-20180416_004128_098625_FB210FF4 X-CRM114-Status: GOOD ( 11.69 ) 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 Remove max_sector_size from struct mtk_nfc_caps, and use sector size array and number of sector size to show sector sizes that controller supports. Signed-off-by: Xiaolei Li --- drivers/mtd/nand/raw/mtk_nand.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c index 6977da3..03a4df2 100644 --- a/drivers/mtd/nand/raw/mtk_nand.c +++ b/drivers/mtd/nand/raw/mtk_nand.c @@ -106,10 +106,11 @@ struct mtk_nfc_caps { const u8 *spare_size; u8 num_spare_size; + const int *sector_size; + int num_sector_size; u8 pageformat_spare_shift; u8 nfi_clk_div; u8 max_sector; - u32 max_sector_size; }; struct mtk_nfc_bad_mark_ctl { @@ -178,6 +179,14 @@ struct mtk_nfc { 16, 26, 27, 28 }; +static const int sector_size_max_1k[] = { + 1024, 512 +}; + +static const int sector_size_max_512[] = { + 512 +}; + static inline struct mtk_nfc_nand_chip *to_mtk_nand(struct nand_chip *nand) { return container_of(nand, struct mtk_nfc_nand_chip, nand); @@ -258,6 +267,16 @@ static inline u8 nfi_readb(struct mtk_nfc *nfc, u32 reg) return readb_relaxed(nfc->regs + reg); } +static int mtk_nfc_max_sector_size(struct mtk_nfc *nfc) +{ + int i, sector_size = 0; + + for (i = 0; i < nfc->caps->num_sector_size; i++) + sector_size = max(sector_size, nfc->caps->sector_size[i]); + + return sector_size; +} + static void mtk_nfc_hw_reset(struct mtk_nfc *nfc) { struct device *dev = nfc->dev; @@ -1207,7 +1226,7 @@ static int mtk_nfc_ecc_init(struct device *dev, struct mtd_info *mtd) */ if (nand->ecc.size < 1024) { if (mtd->writesize > 512 && - nfc->caps->max_sector_size > 512) { + mtk_nfc_max_sector_size(nfc) > 512) { nand->ecc.size = 1024; nand->ecc.strength <<= 1; } else { @@ -1389,28 +1408,31 @@ static int mtk_nfc_nand_chips_init(struct device *dev, struct mtk_nfc *nfc) static const struct mtk_nfc_caps mtk_nfc_caps_mt2701 = { .spare_size = spare_size_mt2701, .num_spare_size = 16, + .sector_size = sector_size_max_1k, + .num_sector_size = 2, .pageformat_spare_shift = 4, .nfi_clk_div = 1, .max_sector = 16, - .max_sector_size = 1024, }; static const struct mtk_nfc_caps mtk_nfc_caps_mt2712 = { .spare_size = spare_size_mt2712, .num_spare_size = 19, + .sector_size = sector_size_max_1k, + .num_sector_size = 2, .pageformat_spare_shift = 16, .nfi_clk_div = 2, .max_sector = 16, - .max_sector_size = 1024, }; static const struct mtk_nfc_caps mtk_nfc_caps_mt7622 = { .spare_size = spare_size_mt7622, .num_spare_size = 4, + .sector_size = sector_size_max_512, + .num_sector_size = 1, .pageformat_spare_shift = 4, .nfi_clk_div = 1, .max_sector = 8, - .max_sector_size = 512, }; static const struct of_device_id mtk_nfc_id_table[] = {