[{"id":1770031,"web_url":"http://patchwork.ozlabs.org/comment/1770031/","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>  \n\n--\nTo unsubscribe from this list: send the line \"unsubscribe linux-pwm\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at  http://vger.kernel.org/majordomo-info.html","headers":{"Return-Path":"<linux-pwm-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-pwm-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xwh8r6Spqz9ryv\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 19:51:08 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932158AbdIRJvH (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tMon, 18 Sep 2017 05:51:07 -0400","from mail.free-electrons.com ([62.4.15.54]:59448 \"EHLO\n\tmail.free-electrons.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1753836AbdIRJvF (ORCPT\n\t<rfc822; linux-pwm@vger.kernel.org>); Mon, 18 Sep 2017 05:51:05 -0400","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)"],"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>","Cc":"Nicolas Ferre <nicolas.ferre@microchip.com>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tMichael Turquette <mturquette@baylibre.com>,\n\tStephen Boyd <sboyd@codeaurora.org>,\n\tLudovic Desroches <ludovic.desroches@microchip.com>,\n\tWenyou Yang <wenyou.yang@atmel.com>, Josh Wu <rainyfeeling@outlook.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tThierry Reding <thierry.reding@gmail.com>,\n\tRichard Genoud <richard.genoud@gmail.com>,\n\tGreg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\tAlan Stern <stern@rowland.harvard.edu>,\n\tlinux-pwm@vger.kernel.org, linux-usb@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,\n\tlinux-serial@vger.kernel.org, linux-clk@vger.kernel.org,\n\tlinux-arm-kernel@lists.infradead.org","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","Content-Type":"text/plain; charset=US-ASCII","Content-Transfer-Encoding":"7bit","Sender":"linux-pwm-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-pwm.vger.kernel.org>","X-Mailing-List":"linux-pwm@vger.kernel.org"}}]