Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1646653imm; Fri, 7 Sep 2018 04:00:13 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb/qTPElmvooDx5IK8mcpKoY4zyTnUpoQCd2DtgmfUQVBRRCe5Llx/HV2EP3vnQreREkFSG X-Received: by 2002:a17:902:a987:: with SMTP id bh7-v6mr7535131plb.182.1536318013334; Fri, 07 Sep 2018 04:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536318013; cv=none; d=google.com; s=arc-20160816; b=1KTgkzGniN98OE2EWNse+cHnfjOuhWAZbbzh6rUt6bk8y7cQBpDfapwK6pUWtVTfVB MaqiWaSdWoFsvm22PvQZaYtnxawoO2I5E/njWFd3Xz7kLptIP1iqK6CsfWC4ssl/DfzT dg99YjH8Go6BKIOE996LoThJrRmx8Lbb5ZushiobHy3Dagp2XnfrdvGj00cdX8PeWtTb HoEyeXhqQE5OTbBNFpTSMud09P6o4l4AzDftaOEwFA1dlqklpbEvCEMBl960XotMQfzJ qpFAGWy255+qScWm8AG8oIWbRtfkWnLOOfWMVCkVM1gQS93TceLUiwHzq+7IpABqo0bw Z9Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=W6nKaDCq5H+lRotH516n4i68olVKz8rMPFmQkHcI3Hg=; b=wPuEVuEyEtU759YjtT2lpgtPKarc9hwBsnUeuARsxkprw5R50LXB2YbE3YRvIw7V0n oSCzEvBm7qSEMhYottjIH7sjZ7MQdlA/QUT/HTny9m5Dia8LbonUuBNCcy/lkbpfY9Rz odhKevevhTom1dBHKsSuUvC3QujT8gsWwYmJMCb0iVoyr4OS9a5F3ctn3LFOEfMN33Gh 47rQ91F1eR3wn5pzpDKl8hO0YY1uS7Zt6x90OOpeUUiLv03RQ57LIv2EiXtZnD5JgqXu V2C9+kzDvffcEIFBcBEgDIsR+OAClk8OliSkuOSjZ2j9yhb4Z6kf8ti+254uRufhM4Fn pMqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=neLsIV6W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65-v6si8067052pld.451.2018.09.07.03.59.57; Fri, 07 Sep 2018 04:00:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=neLsIV6W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbeIGPjB (ORCPT + 99 others); Fri, 7 Sep 2018 11:39:01 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:52249 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728685AbeIGPjB (ORCPT ); Fri, 7 Sep 2018 11:39:01 -0400 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 Cc: Dinh Nguyen , Masahiro Yamada , linux-kernel@vger.kernel.org, Marek Vasut , Brian Norris , Richard Weinberger , David Woodhouse , Mark Rutland 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) 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; -- 2.7.4