From patchwork Fri Sep 7 10:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 146206 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1015849ljw; Fri, 7 Sep 2018 03:57:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbwEm6UKKqk5WQvLHieqaJMzTPlvloYC5FAl8+P9l0f6HhQPmlTS7f6WNgMZaqDnInltBHB X-Received: by 2002:a17:902:934c:: with SMTP id g12-v6mr7344148plp.67.1536317873963; Fri, 07 Sep 2018 03:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536317873; cv=none; d=google.com; s=arc-20160816; b=CB1P7thcJt1hEN4up/tgifrOip9SQKC+t3qOE0mZ4q2qTNiJpaMpL2qG4TNaZSYgrq vAoA9+2yf1mX/znAtcjBdnar459+B/pGR2EItunriCAEFQIlOkIZf2HsuCNDexvO4WE8 ZKqBGei+LshJRrD3wB4f0i6eai48u005VaG81jac3Mma8MyjGV+jJetUErZjqkZXetiN 1VGkoRjysBGZgBQuC9C19/q4Mdg2B5ur1+Wq/cqoBOx9pRLXgUwHIkuJKEkndVXmFU6+ oq8gtf/nIvE+ccAbM2YXIOUwejRZ38hal3lrgkoERnhKZDNxHdR5WveKLCo4Bflo+0x9 ld3g== 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=ISt3juXbdVUdOpfZ5XOpmCKw5EWLWO4oF78RncXeWsM=; b=n+xRyS94VJR++TS8ReN3yo8/rNY4kjtKzkZgcVV5VB7PMnPXmAjQ58qIMCdczm/S2k qOkS7EAvOggUKu9fAFq5gjUYnrWYemtu89pvNaXdRXPgItGg/iB05NLHscjL3TpQBs5D Hpt/E8b0+Vl7x9PmXRJHMgbovfTMBzaSwrLSTzLbwv0chwMEe+ReZh03MgL6LDgr6E2G JN7vfV92AuUOrMKRczUUpxqfQ4aeb31eEUVuBkt524mcAutyZUeNWi1H+g4b77NLmgDN xc3EYgHRxeqk4GLq8CvjzFPwQgrwVgCjIUvbEHmOAiwqAnupcfcajGX5p+BUy78Rij7Z FmAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=RtiXEyl6; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=neLsIV6W; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 198.137.202.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. [198.137.202.133]) by mx.google.com with ESMTPS id a15-v6si8952813pln.137.2018.09.07.03.57.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Sep 2018 03:57:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 198.137.202.133 as permitted sender) client-ip=198.137.202.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=RtiXEyl6; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=neLsIV6W; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 198.137.202.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=ISt3juXbdVUdOpfZ5XOpmCKw5EWLWO4oF78RncXeWsM=; b=Rti XEyl6k1giqfC9Ol+46S+NSUskEHrWRDzK3p8/sLGC97EWLyOvzEdPf71hXFrZcWl7pdeIA7OZwrgp 9xUAs5Ut64f0RW8gT+rntkm1Y9CfnBD34gdAANDF96RZ+wtbQgXGsztrchxkQEpe7b0PCmAI3W8CE Lrte8u1WAztC+bc5Oa1tCiGff7ku9/3DWhUvR9yYGfF/g3uO6/IPnraXCmTK7JoGdb9IMwKCISkwE NoZwvSE7JiyGXrhpwoqH0BrWbgjFhqETdk+odzoK0wiQtQpDbVvLO2yGsLieecPdTkQ8CEDYc+ULr u4J1gNKLcKepcuzf+Ty2PWiI3k4SGDQ==; 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 1fyESK-0006rE-IL; Fri, 07 Sep 2018 10:57:40 +0000 Received: from conuserg-10.nifty.com ([210.131.2.77]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyESF-0006jb-1e for linux-mtd@lists.infradead.org; Fri, 07 Sep 2018 10:57:38 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w87AucWC006019; Fri, 7 Sep 2018 19:56:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w87AucWC006019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1536317799; bh=W6nKaDCq5H+lRotH516n4i68olVKz8rMPFmQkHcI3Hg=; h=From:To:Cc:Subject:Date:From; b=neLsIV6WnRN35Gsm+j1zOfq9HZhHjvGz8TAniln5FJdhtqqOLK0s9X7NUv6LHHlge riMP1b5Jwhy+7tL6R0a7TXrCkGKUEoA61p4jSXHALcvsENszPOqjZidropwLDGoASZ eGmd4h//Ce+h6NQi8cLpeJm8htICozE2d1lcm+JTWyW0ycLWzGlwNMfBflCm/PlOCU howZl9Pf5nF+isQUpXu4OnipdwlMg3TVadK20d9cSnwn/eLi6YouOb9Mt0c7hG+nao CR6ZtCTpDWdjmoVtSqkN53y0k7X73Kp6Qj94o6QEi/SssBeFVvw2TGfpE9xhs+aiiu L74SiMnDyOGGg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org, Boris Brezillon , Miquel Raynal , devicetree@vger.kernel.org, Rob Herring Subject: [PATCH] mtd: rawnand: denali: add DT property to specify skipped bytes in OOB Date: Fri, 7 Sep 2018 19:56:23 +0900 Message-Id: <1536317783-4942-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-20180907_035735_369228_92E421DB X-CRM114-Status: GOOD ( 18.05 ) 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 ---- ---------------------- -------------------------------------------------- 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 -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [210.131.2.77 listed in list.dnswl.org] 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: Mark Rutland , 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. You cannot support the reset control either because resetting the controller will get register values lost. This commit adds a way to specify it via DT. If the property "denali,oob-skip-bytes" exists, the value will be set to the register. Signed-off-by: Masahiro Yamada --- I thought this feature was common enough, but I could not find any relevant property. I added "denali," vendor prefix. If you have a better property name (or a better way to specify the value), please suggest it. Documentation/devicetree/bindings/mtd/denali-nand.txt | 3 +++ drivers/mtd/nand/raw/denali.c | 14 +++++++++----- drivers/mtd/nand/raw/denali_dt.c | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/Documentation/devicetree/bindings/mtd/denali-nand.txt b/Documentation/devicetree/bindings/mtd/denali-nand.txt index f33da87..453faca 100644 --- a/Documentation/devicetree/bindings/mtd/denali-nand.txt +++ b/Documentation/devicetree/bindings/mtd/denali-nand.txt @@ -22,6 +22,9 @@ Optional properties: 8, 16, 24 for "socionext,uniphier-denali-nand-v5a" 8, 16 for "socionext,uniphier-denali-nand-v5b" - nand-ecc-maximize: see nand.txt for details + - denali,oob-skip-bytes: number of bytes to reserve from the start of OOB. + The reserved bytes should not be used for ECC or any other purpose. + It is generally intended to preserve bad block markers. The device tree may optionally contain sub-nodes describing partitions of the address space. See partition.txt for more detail. diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index d1ae968..3ef3f0d 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -1050,12 +1050,16 @@ 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. + * If oob_skip_bytes is specified (e.g. by DT property), set it to the + * reigster. Otherwise, read the value out that may be set by firmware. */ - denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); + if (denali->oob_skip_bytes) + iowrite32(denali->oob_skip_bytes, + denali->reg + SPARE_AREA_SKIP_BYTES); + else + denali->oob_skip_bytes = ioread32(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); diff --git a/drivers/mtd/nand/raw/denali_dt.c b/drivers/mtd/nand/raw/denali_dt.c index 7c6a8a4..bc93675 100644 --- a/drivers/mtd/nand/raw/denali_dt.c +++ b/drivers/mtd/nand/raw/denali_dt.c @@ -78,6 +78,7 @@ static int denali_dt_probe(struct platform_device *pdev) struct denali_dt *dt; const struct denali_dt_data *data; struct denali_nand_info *denali; + u32 oob_skip; int ret; dt = devm_kzalloc(dev, sizeof(*dt), GFP_KERNEL); @@ -155,6 +156,11 @@ static int denali_dt_probe(struct platform_device *pdev) denali->clk_x_rate = 200000000; } + ret = of_property_read_u32(dev->of_node, "denali,oob-skip-bytes", + &oob_skip); + if (!ret) + denali->oob_skip_bytes = oob_skip; + ret = denali_init(denali); if (ret) goto out_disable_clk_ecc;