From patchwork Wed Oct 28 00:14:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 7505491 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DF8CDBEEA4 for ; Wed, 28 Oct 2015 00:17:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E228D20842 for ; Wed, 28 Oct 2015 00:17:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF5BF207F1 for ; Wed, 28 Oct 2015 00:17:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZrEOY-00011u-4y; Wed, 28 Oct 2015 00:15:14 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZrEOR-0008GO-SS; Wed, 28 Oct 2015 00:15:08 +0000 Received: by pabla5 with SMTP id la5so44211763pab.0; Tue, 27 Oct 2015 17:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=CfWQK79k4n5gks2nT0tsnnf9h8EDcCBlPhb8vvfWRgc=; b=tplJKhtsPg9Yg2afc9Ip7jYJj2K1BMWotP0f8aPsTsKB8IbCqUqOITqjVrIom0jOMJ k6MyEvFkalQloNBuHXkhBzvJlDxGzN5Om5X/1x2oALj0siQpoOqcY1njzotalqnN+ZXx KinzxB6yyt4VKwWBT1OtpnH/nD9UZdwg45Cg6/ht9ot8tH58ty8hH87Irq32t302LKTG TMzzu3spDub0oshHztqA7brC5VwW7aFAak9WRi2YFLd2ru4rRjA/YpgzDI0sRzL9h0xu o17Yr9sgFYsv++jJx++EAa8kxRvY/p6yd4Dn69PWS3ItFqVOzzqkXOPYNPDoMqTr1hdf a2Lg== X-Received: by 10.66.230.195 with SMTP id ta3mr31104844pac.35.1445991286249; Tue, 27 Oct 2015 17:14:46 -0700 (PDT) Received: from google.com ([2620:0:1000:1301:69dc:8af3:1d71:215a]) by smtp.gmail.com with ESMTPSA id ug4sm41847546pac.11.2015.10.27.17.14.44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Oct 2015 17:14:45 -0700 (PDT) Date: Tue, 27 Oct 2015 17:14:43 -0700 From: Brian Norris To: Anup Patel Subject: Re: [PATCH v3 1/2] mtd: brcmnand: Force 8bit mode before doing nand_scan_ident() Message-ID: <20151028001443.GX13239@google.com> References: <1445577373-21252-1-git-send-email-anup.patel@broadcom.com> <1445577373-21252-2-git-send-email-anup.patel@broadcom.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1445577373-21252-2-git-send-email-anup.patel@broadcom.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151027_171507_995116_DC812E2A X-CRM114-Status: GOOD ( 23.04 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Device Tree , Florian Fainelli , Scott Branden , Pawel Moll , Ian Campbell , Catalin Marinas , Kumar Gala , Will Deacon , Linux Kernel , Ray Jui , Vikram Prakash , Rob Herring , Linux MTD , Sandeep Tripathy , Sudeep Holla , Pramod KUMAR , BCM Kernel Feedback , David Woodhouse , Linux ARM Kernel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Oct 23, 2015 at 10:46:12AM +0530, Anup Patel wrote: > Just like other NAND controllers, the NAND READID command only works > in 8bit mode for all versions of BRCMNAND controller. > > This patch forces 8bit mode for each NAND CS in brcmnand_init_cs() > before doing nand_scan_ident() to ensure that BRCMNAND controller > is in 8bit mode when NAND READID command is issued. > > Signed-off-by: Anup Patel > Reviewed-by: Ray Jui > Reviewed-by: Scott Branden > --- > drivers/mtd/nand/brcmnand/brcmnand.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c > index 4cba03d..0be8ef9 100644 > --- a/drivers/mtd/nand/brcmnand/brcmnand.c > +++ b/drivers/mtd/nand/brcmnand/brcmnand.c > @@ -1888,6 +1888,7 @@ static int brcmnand_init_cs(struct brcmnand_host *host) > struct mtd_info *mtd; > struct nand_chip *chip; > int ret; > + u16 cfg_offs; > struct mtd_part_parser_data ppdata = { .of_node = dn }; > > ret = of_property_read_u32(dn, "reg", &host->cs); > @@ -1930,6 +1931,14 @@ static int brcmnand_init_cs(struct brcmnand_host *host) > > chip->controller = &ctrl->controller; > > + /* > + * The bootloader might have configured 16bit mode but > + * NAND READID command only works in 8bit mode. We force > + * 8bit mode here to ensure that NAND READID commands works. > + */ > + cfg_offs = brcmnand_cs_offset(ctrl, host->cs, BRCMNAND_CS_CFG); > + nand_writereg(ctrl, cfg_offs, nand_readreg(ctrl, cfg_offs) & ~BIT(23)); Can we get a new enum for cfg bits? Unfortunately, I never managed that in brcmnand_set_cfg(); just magic numbers :( But I'd like to stop that if we're going to have to touch these bits outside of brcmnand_set_cfg(). > + > if (nand_scan_ident(mtd, 1, NULL)) > return -ENXIO; > How about the following, as a preparatory patch? Only compile tested. From c5423a86dbfa33b550d2b170bda3c12ecf4d5313 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 27 Oct 2015 17:12:13 -0700 Subject: [PATCH] mtd: brcmnand: factor out CFG and CFG_EXT bitfields These used magic numbers. Shame on me. Signed-off-by: Brian Norris Cc: Anup Patel --- drivers/mtd/nand/brcmnand/brcmnand.c | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c index d694d876631e..c93fbc3869ee 100644 --- a/drivers/mtd/nand/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/brcmnand/brcmnand.c @@ -344,6 +344,28 @@ static const u8 brcmnand_cs_offsets_cs0[] = { [BRCMNAND_CS_TIMING2] = 0x14, }; +/* + * Bitfields for the CFG and CFG_EXT registers. Pre-v7.1 controllers only had + * one config register, but once the bitfields overflowed, newer controllers + * (v7.1 and newer) added a CFG_EXT register and shuffled a few fields around. + */ +enum { + CFG_BLK_ADR_BYTES_SHIFT = 8, + CFG_COL_ADR_BYTES_SHIFT = 12, + CFG_FUL_ADR_BYTES_SHIFT = 16, + CFG_BUS_WIDTH_SHIFT = 23, + CFG_BUS_WIDTH = BIT(CFG_BUS_WIDTH_SHIFT), + CFG_DEVICE_SIZE_SHIFT = 24, + + /* Only for pre-v7.1 (with no CFG_EXT register) */ + CFG_PAGE_SIZE_SHIFT = 20, + CFG_BLK_SIZE_SHIFT = 28, + + /* Only for v7.1+ (with CFG_EXT register) */ + CFG_EXT_PAGE_SIZE_SHIFT = 0, + CFG_EXT_BLK_SIZE_SHIFT = 4, +}; + /* BRCMNAND_INTFC_STATUS */ enum { INTFC_FLASH_STATUS = GENMASK(7, 0), @@ -1710,17 +1732,19 @@ static int brcmnand_set_cfg(struct brcmnand_host *host, } device_size = fls64(cfg->device_size) - fls64(BRCMNAND_MIN_DEVSIZE); - tmp = (cfg->blk_adr_bytes << 8) | - (cfg->col_adr_bytes << 12) | - (cfg->ful_adr_bytes << 16) | - (!!(cfg->device_width == 16) << 23) | - (device_size << 24); + tmp = (cfg->blk_adr_bytes << CFG_BLK_ADR_BYTES_SHIFT) | + (cfg->col_adr_bytes << CFG_BLK_ADR_BYTES_SHIFT) | + (cfg->ful_adr_bytes << CFG_FUL_ADR_BYTES_SHIFT) | + (!!(cfg->device_width == 16) << CFG_BUS_WIDTH_SHIFT) | + (device_size << CFG_DEVICE_SIZE_SHIFT); if (cfg_offs == cfg_ext_offs) { - tmp |= (page_size << 20) | (block_size << 28); + tmp |= (page_size << CFG_PAGE_SIZE_SHIFT) | + (block_size << CFG_BLK_SIZE_SHIFT); nand_writereg(ctrl, cfg_offs, tmp); } else { nand_writereg(ctrl, cfg_offs, tmp); - tmp = page_size | (block_size << 4); + tmp = (page_size << CFG_EXT_PAGE_SIZE_SHIFT) | + (block_size << CFG_EXT_BLK_SIZE_SHIFT); nand_writereg(ctrl, cfg_ext_offs, tmp); }