From patchwork Fri Sep 28 04:16:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 147757 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp250219lji; Thu, 27 Sep 2018 21:18:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV636ZPWCmDiExXur9T/rNDH5+cTUpZZxDfUZnQSR465G7SPbVOLwbzjrA68BmsXSewcCbgZD X-Received: by 2002:a62:20d8:: with SMTP id m85-v6mr1159433pfj.152.1538108317180; Thu, 27 Sep 2018 21:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538108317; cv=none; d=google.com; s=arc-20160816; b=kyZAjqtBpfAi+H0ch3CTrsa+b4dTppVk7EfWjBLyJ1+vtmcFbPMOpYJFXnSx4MF17F 7psytDtXfQovq0S2HR0jKPA1PSMZpP41JmVlwkCJ1EhOHpLSTdRtIVnutTemWxamtz5W sElLAVc4BcEM+tfPZuAPp+tm9P2/M8sX6aQEYl+OrWqjfBWOR0zRZQr2Br4TDJMPqDCy STwjzwgfAJoXsbVzn8SuXZHqumh1K8rMftK8yBE0V99k9R/Tyfw7aehtmLcIuQZZ+yuU C1yXM3Uzab8ZqA34s7YGT0j9R88J5SXe9fzGPBE9JFPDSfoGMHxGXLVSMkl0+am65GVd jmUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:message-id:date:subject:to:from:dkim-signature :dkim-filter:dkim-signature; bh=9LsRFjzcQ71BHja0vvQEL/RXVrlfFhAvci574WBtRpI=; b=sdEYFjyztPYxzn/AMHtVWAYJVorUS3/6Yp3fHlgsx75Q1mRu4Yk9K4VzifHT6Bhhdk mXONGPFkHAUb0t86d+MrQQNYEmq6cZi2JMSLqS8bXadEgSx5iyE8guvFisiIvijV7Ses miNLtlSMugWj3Hwr1Rzf3+zneMCjzRjIA4Jm+mubxfmSODoFDu6/+M39bbro+A8kieZi MbPYYhkNc7T/V28V7C0ZJC3XSlwEcOR16jISEeiKM08Vdx9/UenDQMKV0VydWTXUzAAR s2uLB2EtF9X7PtcvalampjUItprlMnBJW0DCNAnnLV3v+qYneJKyDc2TJ9Y/1WwA8JKC kR2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=c4mgLUeg; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=kfe9FpKV; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id v33-v6si3746776pga.450.2018.09.27.21.18.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Sep 2018 21:18:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=c4mgLUeg; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=kfe9FpKV; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org" 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To: References:List-Owner; bh=9LsRFjzcQ71BHja0vvQEL/RXVrlfFhAvci574WBtRpI=; b=c4m gLUeg2cih0UDUniqxlFJIialcze85COF50JdnWvO3ixS/sYP/mESvui9o5RZdNpYSSk5tuXV51LWL 4XrMJTL2DfCNnBFY4iyY8GXADVF7lmxmULcbAu0LUvyqqMMJXfSr4U1sHWADC6cj6gxJ74ryXWaVf nGcEFh3x4owRgIH0aUT+9zCFy3dhyvwZJpNRI+0Ph0180Ox9OtZGBEvN1/zy83qF0Sn56E8Ky6Fqw Mn14XpEGgz5U2BVt+DTVZKZ+h7GCF91yqZ4rWKtK/n98ATog5cdvpHfArx8IBOvF65qHWIrLnpffA Lk8fp1QmKCfIPvM/+EV+hAcqIQNfrlA==; 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 1g5kEK-0007j3-QQ; Fri, 28 Sep 2018 04:18:16 +0000 Received: from conuserg-11.nifty.com ([210.131.2.78]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5kDG-0007fb-Hb for linux-mtd@lists.infradead.org; Fri, 28 Sep 2018 04:17:12 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id w8S4GAxq019811; Fri, 28 Sep 2018 13:16:10 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com w8S4GAxq019811 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1538108171; bh=XL2TtXqIYxPVBf8vNRR9UfPcC/SEkEpUo0i1xrrDfZ8=; h=From:To:Cc:Subject:Date:From; b=kfe9FpKViw5nw7359ws71cnd97aOKlI0elNs03FjGK5e+1ar32HFgAGDpiM7wgZ/f HFSB97gBGBfl4ckdRWkuCZ1LGvBu6wsIhAdh0cPgFLhQJoM8LvGLK2/ymYQjM6wBuy v30Ms2fp2Urt04NIrONqxsCLHSaLGM6NnyK+ola+rArI43ZRnsny/XmUJp4uY+M+NM e2faTQtevwcvyHabAgifk1MuHhzw1dffm1PT6z8vySbddLhPudT8l/LfKxv3Y3Qg4O 4vdA7H3U/R7xlekDkrVFEwgYXldAYzxYDjcps65tHj5EOEkUmVStV2bpotaSQA2B49 rtB6N5yoZvvNA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal Subject: [PATCH v2] mtd: rawnand: denali: set SPARE_AREA_SKIP_BYTES register to 8 if unset Date: Fri, 28 Sep 2018 13:16:01 +0900 Message-Id: <1538108161-6174-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_211710_940215_FB409692 X-CRM114-Status: GOOD ( 16.54 ) X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [210.131.2.78 listed in list.dnswl.org] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Masahiro Yamada , Richard Weinberger , linux-kernel@vger.kernel.org, Dinh Nguyen , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org NAND devices need additional data area (OOB) for error correction, but it is also used for Bad Block Marker (BBM). In many cases, the first byte in OOB is used for BBM, but the location actually depends on chip vendors. The NAND controller should preserve the precious BBM to keep track of bad blocks. In Denali IP, the SPARE_AREA_SKIP_BYTES register is used to specify the number of bytes to skip from the start of OOB. The ECC engine will automatically skip the specified number of bytes when it gets access to OOB area. The same value for SPARE_AREA_SKIP_BYTES should be used between firmware and the operating system if you intend to use the NAND device across the control hand-off. In fact, the current denali.c code expects firmware to have already set the SPARE_AREA_SKIP_BYTES register, then reads the value out. If no firmware (or bootloader) has initialized the controller, the register value is zero, which is the default after power-on-reset. In other words, the Linux driver cannot initialize the controller by itself. Some possible solutions are: [1] Add a DT property to specify the skipped bytes in OOB [2] Associate the preferred value with compatible [3] Hard-code the default value in the driver My first attempt was [1], but in the review process, [3] was suggested as a counter-implementation. (https://lore.kernel.org/patchwork/patch/983055/) The default value 8 was chosen to match to the boot ROM of the UniPhier platform. The preferred value may vary by platform. If so, please trade up to a different solution. Signed-off-by: Masahiro Yamada --- Changes in v2: - Change approach from a DT-property to a hard-coded dafault drivers/mtd/nand/raw/denali.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index aaab121..18bbfc8 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -21,6 +21,7 @@ #include "denali.h" #define DENALI_NAND_NAME "denali-nand" +#define DENALI_DEFAULT_OOB_SKIP_BYTES 8 /* for Indexed Addressing */ #define DENALI_INDEXED_CTRL 0x00 @@ -1056,12 +1057,17 @@ static void denali_hw_init(struct denali_nand_info *denali) denali->revision = swab16(ioread32(denali->reg + REVISION)); /* - * tell driver how many bit controller will skip before - * writing ECC code in OOB, this register may be already - * set by firmware. So we read this value out. - * if this value is 0, just let it be. + * Set how many bytes should be skipped before writing data in OOB. + * If a non-zero value has already been set (by firmware or something), + * just use it. Otherwise, set the driver default. */ denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); + if (!denali->oob_skip_bytes) { + denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; + iowrite32(denali->oob_skip_bytes, + denali->reg + SPARE_AREA_SKIP_BYTES); + } + denali_detect_max_banks(denali); iowrite32(0x0F, denali->reg + RB_PIN_ENABLED); iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);