Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753287AbcKZSMR (ORCPT ); Sat, 26 Nov 2016 13:12:17 -0500 Received: from conuserg-11.nifty.com ([210.131.2.78]:48286 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753239AbcKZSI1 (ORCPT ); Sat, 26 Nov 2016 13:08:27 -0500 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com uAQI6Uf1018512 X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org, Boris Brezillon , Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse , Cyrille Pitchen Subject: [PATCH 29/39] mtd: nand: denali: refactor multi NAND fixup code in more generic way Date: Sun, 27 Nov 2016 03:06:15 +0900 Message-Id: <1480183585-592-30-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480183585-592-1-git-send-email-yamada.masahiro@socionext.com> References: <1480183585-592-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2434 Lines: 71 Currently, this code expects denali->devnum == 1 or 2, but it can be written in a more generic way, although denali->devnum should be a power of 2. Also, make the code more readable with devnum_shift. Signed-off-by: Masahiro Yamada --- drivers/mtd/nand/denali.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 54dcd83..71bdf2a 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -1476,6 +1476,7 @@ static void denali_multidev_fixup(struct denali_nand_info *denali) { struct nand_chip *chip = &denali->nand; struct mtd_info *mtd = nand_to_mtd(chip); + int devnum_shift; /* * Support for multi NAND: @@ -1484,20 +1485,30 @@ static void denali_multidev_fixup(struct denali_nand_info *denali) */ denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED); - mtd->size <<= denali->devnum - 1; - mtd->erasesize <<= denali->devnum - 1; - mtd->writesize <<= denali->devnum - 1; - mtd->oobsize <<= denali->devnum - 1; - chip->chipsize <<= denali->devnum - 1; - chip->page_shift += denali->devnum - 1; - chip->phys_erase_shift += denali->devnum - 1; - chip->bbt_erase_shift += denali->devnum - 1; - chip->chip_shift += denali->devnum - 1; - chip->pagemask <<= denali->devnum - 1; - chip->ecc.size *= denali->devnum; - chip->ecc.bytes *= denali->devnum; - chip->ecc.strength *= denali->devnum; - denali->bbtskipbytes *= denali->devnum; + devnum_shift = fls(denali->devnum) - 1; + + if (denali->devnum != BIT(devnum_shift)) { + dev_warn(denali->dev, + "DEVICE_CONNECTED=%d is not power of 2. Some devices will not be used.\n", + denali->devnum); + denali->devnum = BIT(devnum_shift); + iowrite32(denali->devnum, denali->flash_reg + DEVICES_CONNECTED); + } + + mtd->size <<= devnum_shift; + mtd->erasesize <<= devnum_shift; + mtd->writesize <<= devnum_shift; + mtd->oobsize <<= devnum_shift; + chip->chipsize <<= devnum_shift; + chip->page_shift += devnum_shift; + chip->phys_erase_shift += devnum_shift; + chip->bbt_erase_shift += devnum_shift; + chip->chip_shift += devnum_shift; + chip->pagemask <<= devnum_shift; + chip->ecc.size <<= devnum_shift; + chip->ecc.bytes <<= devnum_shift; + chip->ecc.strength <<= devnum_shift; + denali->bbtskipbytes <<= devnum_shift; } int denali_init(struct denali_nand_info *denali) -- 2.7.4