From patchwork Wed Jan 9 20:55:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 155092 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1141837jaa; Wed, 9 Jan 2019 12:55:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN6+mVxWn9CVSh4sup/HxLS7y3M3uzf06O6nKMp3MGX9Mv4IwfOQCH27LOfdYkSsJ4+/zmUS X-Received: by 2002:a63:f901:: with SMTP id h1mr6839036pgi.154.1547067349700; Wed, 09 Jan 2019 12:55:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547067349; cv=none; d=google.com; s=arc-20160816; b=BR42gubDdbASU9rtjLEtfESUqfoWfsuSC6ZCcBzYjpdyc4GB4tTp+VftbeDCNxuhKY rh54IZS1nx80m1nxBMEEqUZCngxzASt3wJ+yTfQlTDk1zWD0KRa1UC7v3ffab+fYhSmm NlC+z/ovq7YbDuNIJy0RQoxtGJywjvJFpelxfkIWkCsjH1/S07+a3xxzTWfK4HZ/a6ZL LN99XAkE5L9Z3zfyio0TkO/YGifLmDRLPXm+0qTu8bcbz0r/AmWnJYLNK4ZDZ4EE6+cq 7olBUmQw8qQd4trTteb9JmNC1zLZSsUNbV4VllY29Ui3v0IcCqziMayDtJpN0i6Az/IV EC5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :dkim-signature:dkim-signature; bh=oNSl8fQDp41OgCAs/X83gFl+DnexjX+SKkntdeijfb4=; b=cJ1brz7BDyL+WtuuxpclDoWSvbdbwepJ7M54g4fIEg241hQaD7LD8s7B7IIpxVryuh 1CPow5fKnuxGnStgjBfrrYmtazsMOtlj9nlsr0U38ED47Nr7yzQLDhUdZEY43eWqCD+0 69L6BKiZFP216GFD4xdxloWP3kMe32RqlWtJCr81oFpSb+06Z+zeJX35EzF/O+X3KQha N8+Es6AqSVyRmDl2gYjK9LPC4Bkj+LuutK3HVZfn0yUPe1ZUhD5lW0hO1NtnGJJDhRhV ASoZ/6xupDB0E1lVdIGAC9ulCHjmrRqRlkLTKVONMMAhib2y0LVc4O4ozE0MhVx9U75N 0BgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=GNOKL5M1; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bkHRHaPB; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id k22si19048533pll.276.2019.01.09.12.55.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Jan 2019 12:55:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=GNOKL5M1; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bkHRHaPB; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=oNSl8fQDp41OgCAs/X83gFl+DnexjX+SKkntdeijfb4=; b=GNOKL5M1GDW2xF BcxpvO3BXtSRjLpJcRMtERrj9+TzG1RVj8md1SKp7fKd8Y5f7q+o5foKAzfSEo4kb4BS23DyYGDDD s7ufPPTXqvEb2imbcnyCkV5++nhmx+LsMeZPX/FHOywRbMigB8LF0N7DrtFVMLKg1OKAkkzJc4kFf uGiu661SalSmnHdkT2d8HHYvEWiBSSHpYtFLy2Rp8ikdkc7fJHpwrpQRPKPIUKD+4+Tl+NuEvwalB /2uop6VIR0sbT0+QSyuge7ZSYgJblWKK9gdRHQr5RXq/Y7wu30SbWsBNSNlbchNs22/x6UQ/1GTY4 cp90KKZZVFaRB6nOkHag==; 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 1ghKt2-0000OH-NE; Wed, 09 Jan 2019 20:55:40 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ghKsz-0000Ne-Vi for linux-mtd@lists.infradead.org; Wed, 09 Jan 2019 20:55:39 +0000 Received: by mail-lf1-x143.google.com with SMTP id e26so6708935lfc.2 for ; Wed, 09 Jan 2019 12:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bgfbdz1rZUmAfBJcDw//KO/JJRTtcTpVJzsSHboY8/o=; b=bkHRHaPBIZHehD66GXXCayGrmueHOUgncuHOFN9HllY0iwFXU4zW4h8kNNXm+miFcI ljDnL6g9CPvMDBEqv5BKYa9Nom9DIHjw8E5uThZpsozLqCW91wreOs0OUQJWx5qp5yEC m/XNL14sU6bp7o/lDx7YDNwq+amDlJbEJ6THg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bgfbdz1rZUmAfBJcDw//KO/JJRTtcTpVJzsSHboY8/o=; b=KCawUqENsLWjbuLw2bAomAgwxh2P85D7fS/Q5VdSEcxMdyEzAPVUGRkRZf2sYFYQV3 Oxamyg4QkB/i0xUP0H2ATJWOvRm1n41/hr0APV17vYLNfgtzAR9bS5Xfl0KeT0qHrWK0 STQv87WDXq0zO8mpv/zi5bR3iI9ix1v0hJjkSrYtchutpGeYPHChI0wjGCU1U0qINN2t j8ZxoyEBNW7BUUHWcKJ0eOUr6+zJOc4Pmnh4tBzUhGjlu1Iy6c70PRNW2gvG2LTRcpq+ /REAjAtA98z5wd7Vmr/wNCST3iwE940TRssnQxu5UlO0QWIfOokX8k7h0F58dbEDs2w4 pQIg== X-Gm-Message-State: AJcUuke46cAUkBt8+NO8vpic/9zk8K0N2eqo/mqG8+HngJPkWcFdSR5G twKb0RE6Zw6wzkNMtqVwfj7dPg== X-Received: by 2002:a19:4402:: with SMTP id r2mr4142278lfa.111.1547067335855; Wed, 09 Jan 2019 12:55:35 -0800 (PST) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id g24sm3232374lfh.33.2019.01.09.12.55.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Jan 2019 12:55:34 -0800 (PST) From: Linus Walleij To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , linux-mtd@lists.infradead.org Subject: [PATCH] mtd: rawnand: fsmc: Keep CE enabled fix mb() drain Date: Wed, 9 Jan 2019 21:55:30 +0100 Message-Id: <20190109205530.5158-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190109_125538_017843_2AE00FE4 X-CRM114-Status: GOOD ( 23.05 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:143 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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: Linus Walleij Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Hammering the chip enable on and off between every command crashes the Nomadik NHK15 with this message: Scanning device for bad blocks Unhandled fault: external abort on non-linefetch (0x008) at 0xcc95e000 pgd = (ptrval) [cc95e000] *pgd=0b808811, *pte=40000653, *ppte=40000552 Internal error: : 8 [#1] PREEMPT ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.20.0-rc2+ #72 Hardware name: Nomadik STn8815 PC is at fsmc_exec_op+0x194/0x204 (...) This patch keeps the CE (chip enable, the only chip select) signal from the FSMC block enabled from the first command after probe() or resume() until the driver either suspend() or remove(). Create a state variable to track this. Runtime PM can possibly be used on top of this approach if we want to disable the CE line when no flash read/write is going on for a prolonged time, but for now it stabilizes the platform by simply keeping CE asserted as it used to be. While we're at it also fix the mb() memory barrier drain order (patch folded in from Boris Brezillion). Fixes: 550b9fc4e3af ("mtd: rawnand: fsmc: Stop implementing ->select_chip()") Signed-off-by: Linus Walleij --- drivers/mtd/nand/raw/fsmc_nand.c | 41 ++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) -- 2.19.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/raw/fsmc_nand.c b/drivers/mtd/nand/raw/fsmc_nand.c index 325b4414dccc..442fda905489 100644 --- a/drivers/mtd/nand/raw/fsmc_nand.c +++ b/drivers/mtd/nand/raw/fsmc_nand.c @@ -118,6 +118,7 @@ enum access_mode { * @dev: Parent device * @mode: Access mode * @clk: Clock structure for FSMC. + * @ce_asserted: CE (chip enable) is asserted * * @read_dma_chan: DMA channel for read access * @write_dma_chan: DMA channel for write access to NAND @@ -140,6 +141,7 @@ struct fsmc_nand_data { struct device *dev; enum access_mode mode; struct clk *clk; + bool ce_asserted; /* DMA related objects */ struct dma_chan *read_dma_chan; @@ -598,16 +600,27 @@ static void fsmc_ce_ctrl(struct fsmc_nand_data *host, bool assert) { u32 pc = readl(host->regs_va + FSMC_PC); - if (!assert) + /* Shortcut */ + if (host->ce_asserted) + return; + + if (!assert) { + /* + * Make sure all previous read/write have been done before + * de-asserting the CE line. + */ + mb(); writel_relaxed(pc & ~FSMC_ENABLE, host->regs_va + FSMC_PC); - else + host->ce_asserted = false; + } else { writel_relaxed(pc | FSMC_ENABLE, host->regs_va + FSMC_PC); - - /* - * nCE line changes must be applied before returning from this - * function. - */ - mb(); + /* + * nCE line changes must be applied before returning from this + * function. + */ + mb(); + host->ce_asserted = true; + } } /* @@ -627,6 +640,12 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op, pr_debug("Executing operation [%d instructions]:\n", op->ninstrs); + if (op->cs != 0) { + pr_err("illegal chip select\n"); + fsmc_ce_ctrl(host, false); + return -EINVAL; + } + fsmc_ce_ctrl(host, true); for (op_id = 0; op_id < op->ninstrs; op_id++) { @@ -686,8 +705,6 @@ static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op, } } - fsmc_ce_ctrl(host, false); - return ret; } @@ -1153,6 +1170,8 @@ static int fsmc_nand_remove(struct platform_device *pdev) { struct fsmc_nand_data *host = platform_get_drvdata(pdev); + fsmc_ce_ctrl(host, false); + if (host) { nand_release(&host->nand); @@ -1171,6 +1190,8 @@ static int fsmc_nand_suspend(struct device *dev) { struct fsmc_nand_data *host = dev_get_drvdata(dev); + fsmc_ce_ctrl(host, false); + if (host) clk_disable_unprepare(host->clk);