From patchwork Wed Oct 31 23:03:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149886 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp96998ljp; Wed, 31 Oct 2018 16:06:09 -0700 (PDT) X-Google-Smtp-Source: AJdET5c/DIYyP08MQ80H1nZWuGpbo3To6NHLiy8D93pbfZaTRQg4ziHq4rydUUyibWAYPfzEmr1r X-Received: by 2002:a63:fd58:: with SMTP id m24-v6mr5024481pgj.132.1541027169471; Wed, 31 Oct 2018 16:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027169; cv=none; d=google.com; s=arc-20160816; b=r6JxHoPOsHGvdDgzRcCqgbVTUPXda2fbCv0E9wpqY8fVns+TVLj1rKRLFYZXPjp+er wtWw8PsOBA/TqsicuoBz+ftWlfrx+jX4vld1uwDPKL5pSb6zOZiWFGU1Jb1dh5O+IhtZ NTqrGowdjB9k8GLZ6Q04PHqWct57joZTiWOdoRE4HtJKDCHzPtu5UbblgsI42NY7KMh5 fSrOPOoVleaCiEYxA5U/wHyPvO+Hh+pIslwKOANdIuCwLhIbeUxU5Zo6r5XFhGr2iE+t sGDefIDC8w8DSrODT7V4CrQ5yfs9I5mhYRZkPOzZmIpE36pXI1JQmw8iQIs+4bCjwXoB ZNeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=pvuMmfN1K4TUd7AE+lJ0UA/xNURe31Z9bxpOFNQhAnE=; b=eNkeN9xOovC+DHUTwAOj3oFvn99pBfY2O3FPQI6etAt9r5KyWi/7w3n/sLY7RDBW+E NSkzgbZIRpm/apO+r4JUogXld8bhdEh09lT8wvRl4UPq6vFroiljwMUuDGdFSq/vHSpL 1N/FuHzDfsy9xaiDGLUsDWXppxrRDHLw0y1Fli+UDb69yLpHznnpHQwk631NuEhqqxWX yYW130yMH78UD2E99yS9topw7Hx85xt1zd4dtAg43xzPsJ1ToDuERHqPt8o6NRxkHLBL lPbTV1MnUbdQemTf60nYScbeW1D00vL/CV913nxQjDFtx3sgEvLAp/sBjoe4fYgisMsy LDTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KMq1N/2q"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a23-v6si7930715pls.322.2018.10.31.16.06.09; Wed, 31 Oct 2018 16:06:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b="KMq1N/2q"; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbeKAIGR (ORCPT + 15 others); Thu, 1 Nov 2018 04:06:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727683AbeKAIGR (ORCPT ); Thu, 1 Nov 2018 04:06:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E43A72082E; Wed, 31 Oct 2018 23:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027166; bh=tuEJvDI3bM0wRAyEI8FVDVYwZNrGh0rzXm4cwq5rC7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMq1N/2qXJm8WpusQ3jRJcW4/LNP2XD0w1WpvresoAkSRZjGVbcnDoVlzuZUMv2U2 m3DHsHZ+V7J+2nL+PLPx1c52fmp5YPQZXDy8r28UEPTw5HCPXBSnQwZt1L6WH0mAIN Ajql6lPjgkbMfKyV6CAkji4xQ/bvStW9T45WW1i8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masahiro Yamada , Miquel Raynal , Sasha Levin Subject: [PATCH AUTOSEL 4.19 026/146] mtd: rawnand: denali: set SPARE_AREA_SKIP_BYTES register to 8 if unset Date: Wed, 31 Oct 2018 19:03:41 -0400 Message-Id: <20181031230541.28822-26-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masahiro Yamada [ Upstream commit 0d55c668b218a1db68b5044bce4de74e1bd0f0c8 ] 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 Reviewed-by: Boris Brezillon Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/nand/raw/denali.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index b864b93dd289..2242e999a76b 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -28,6 +28,7 @@ MODULE_LICENSE("GPL"); #define DENALI_NAND_NAME "denali-nand" +#define DENALI_DEFAULT_OOB_SKIP_BYTES 8 /* for Indexed Addressing */ #define DENALI_INDEXED_CTRL 0x00 @@ -1105,12 +1106,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);