[{"id":1770036,"web_url":"http://patchwork.ozlabs.org/comment/1770036/","msgid":"<20170918115052.4606d8e5@bbrezillon>","list_archive_url":null,"date":"2017-09-18T09:50:52","subject":"Re: [PATCH v2 4/9] mtd: nand: atmel: Avoid ECC errors when leaving\n\tbackup mode","submitter":{"id":63120,"url":"http://patchwork.ozlabs.org/api/people/63120/","name":"Boris Brezillon","email":"boris.brezillon@free-electrons.com"},"content":"Hi Romain,\n\nOn Fri, 15 Sep 2017 16:04:06 +0200\nRomain Izard <romain.izard.pro@gmail.com> wrote:\n\n> During backup mode, the contents of all registers will be cleared as the\n> SoC will be completely powered down. For a product that boots on NAND\n> Flash memory, the bootloader will obviously use the related controller\n> to read the Flash and correct any detected error in the memory, before\n> handling back control to the kernel's resuming entry point.\n> \n> In normal devices, it is up to the driver's suspend/resume code to\n> restore the registers in a valid state. But the PMECC is not a regular\n> device in the driver model when used with the legacy device tree binding\n> for the Atmel NAND controller, and suspend/resume code is not called.\n> \n> As in my case the bootloader leaves the PMECC controller in a programmed\n> state, and the controller is only reset at boot or after a NAND access,\n> the first NAND Flash access with the Atmel controller will report\n> uncorrectable ECC errors.\n> \n> To avoid this, systematically reset the PMECC controller before using\n> it.\n> \n> Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>\n> ---\n>  drivers/mtd/nand/atmel/pmecc.c | 11 +++--------\n>  1 file changed, 3 insertions(+), 8 deletions(-)\n> \n> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c\n> index 8c210a5776bc..8d1208f38025 100644\n> --- a/drivers/mtd/nand/atmel/pmecc.c\n> +++ b/drivers/mtd/nand/atmel/pmecc.c\n> @@ -777,6 +777,9 @@ int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op)\n>  \n>  \tmutex_lock(&user->pmecc->lock);\n>  \n> +\twritel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);\n> +\twritel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);\n> +\n>  \tcfg = user->cache.cfg;\n>  \tif (op == NAND_ECC_WRITE)\n>  \t\tcfg |= PMECC_CFG_WRITE_OP;\n> @@ -797,10 +800,6 @@ EXPORT_SYMBOL_GPL(atmel_pmecc_enable);\n>  \n>  void atmel_pmecc_disable(struct atmel_pmecc_user *user)\n>  {\n> -\tstruct atmel_pmecc *pmecc = user->pmecc;\n> -\n> -\twritel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);\n> -\twritel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);\n\nSo know you leave the ECC engine enabled even when it's not in use? Not\nsure what kind of implication this has on power-consumption, but I\nthink I'd prefer to keep the write RST+DISABLE sequence in the disable\npath.\n\nHow about creating a atmel_pmecc_reset() function that you'd call from\nthe nand-controller resume hook. Something like:\n\nvoid atmel_pmecc_reset(struct atmel_pmecc *pmecc)\n{\n\twritel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);\n\twritel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);\n}\n\nThis way you can re-use the same function and call it from the probe\nand disable path as well.\n\nRegards,\n\nBoris\n\n>  \tmutex_unlock(&user->pmecc->lock);\n>  }\n>  EXPORT_SYMBOL_GPL(atmel_pmecc_disable);\n> @@ -856,10 +855,6 @@ static struct atmel_pmecc *atmel_pmecc_create(struct platform_device *pdev,\n>  \t/* Disable all interrupts before registering the PMECC handler. */\n>  \twritel(0xffffffff, pmecc->regs.base + ATMEL_PMECC_IDR);\n>  \n> -\t/* Reset the ECC engine */\n> -\twritel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);\n> -\twritel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);\n> -\n>  \treturn pmecc;\n>  }\n>","headers":{"Return-Path":"<linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"g4V+6dmY\"; \n\tdkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xwhCV2lsPz9ryv\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 19:53:26 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dtsjp-0002iD-99; Mon, 18 Sep 2017 09:53:13 +0000","from mail.free-electrons.com ([62.4.15.54])\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dtsi4-0001UH-GA; Mon, 18 Sep 2017 09:52:21 +0000","by mail.free-electrons.com (Postfix, from userid 110)\n\tid E863021D26; Mon, 18 Sep 2017 11:51:02 +0200 (CEST)","from bbrezillon (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr\n\t[90.63.216.87])\n\tby mail.free-electrons.com (Postfix) with ESMTPSA id 633C220F69;\n\tMon, 18 Sep 2017 11:50:52 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=urIQFEupGreZzzkkaneA37MMw8brXIJ/24lofI4fbm8=;\n\tb=g4V+6dmY/rl6Sm\n\toQkTN3CUnOs5zo9Uv9qgyl/x2rrHXSlVy4obnVxN6hivvsGNg9dmgqWeqcwYfCCjv/ZcDtlFy9UJM\n\tCGvluJsAgBEBFdjMDe0mXzefLgJ203CiDP1xEOW4+Tq4bbIWl+QPpLduPp6W+dOvqcKWOLX7KfF8W\n\t+Dideb6aPNbwturFQSiqRHaDmWTRwF7qDOn5Qczj46qbYmQpl3UyI8M61nkgmgz0z4kEIELLT75N6\n\tHdX4+y98Q4gAaFVIsXcLUBbEgHfXjl4VwGjUr0sBTVoOeftDZ2BwyujAAtVKpgJQBYd1H0/LyLNIz\n\tsRuVms2gUn+lAgb4zbHw==;","X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on\n\tmail.free-electrons.com","X-Spam-Level":"","X-Spam-Status":"No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT\n\tshortcircuit=ham autolearn=disabled version=3.4.0","Date":"Mon, 18 Sep 2017 11:50:52 +0200","From":"Boris Brezillon <boris.brezillon@free-electrons.com>","To":"Romain Izard <romain.izard.pro@gmail.com>","Subject":"Re: [PATCH v2 4/9] mtd: nand: atmel: Avoid ECC errors when leaving\n\tbackup mode","Message-ID":"<20170918115052.4606d8e5@bbrezillon>","In-Reply-To":"<20170915140411.31716-5-romain.izard.pro@gmail.com>","References":"<20170915140411.31716-1-romain.izard.pro@gmail.com>\n\t<20170915140411.31716-5-romain.izard.pro@gmail.com>","X-Mailer":"Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)","MIME-Version":"1.0","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170918_025125_606622_30BC9760 ","X-CRM114-Status":"GOOD (  22.52  )","X-Spam-Score":"-1.9 (-)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-1.9 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 SPF_PASS               SPF: sender matches SPF record\n\t-0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay\n\tdomain\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Cc":"Michael Turquette <mturquette@baylibre.com>, linux-kernel@vger.kernel.org,\n\tThierry Reding <thierry.reding@gmail.com>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tlinux-clk@vger.kernel.org, Josh Wu <rainyfeeling@outlook.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tLudovic Desroches <ludovic.desroches@microchip.com>,\n\tAlan Stern <stern@rowland.harvard.edu>, linux-serial@vger.kernel.org, \n\tlinux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,\n\tRichard Genoud <richard.genoud@gmail.com>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tlinux-usb@vger.kernel.org, Stephen Boyd <sboyd@codeaurora.org>,\n\tNicolas Ferre <nicolas.ferre@microchip.com>,\n\tWenyou Yang <wenyou.yang@atmel.com>,\n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tlinux-mtd@lists.infradead.org, \n\tBrian Norris <computersforpeace@gmail.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"}}]