From patchwork Tue Mar 25 08:19:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26991 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33D5420062 for ; Tue, 25 Mar 2014 08:26:35 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f11sf109721qae.11 for ; Tue, 25 Mar 2014 01:26:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=Rft2UP+79lCc/UZQ3d42AroVoFn221Me5gDdhHtOJFA=; b=bMZy8737Ldfu/FQ1kF3hzghMfPq/qwLmQ8qipHX45/JiwvhdgjFasD1VsOrzWMyEqC PliTwceviqGNfEIQbeE1HerwUZa62uGm8RxSnj2obSaSmzkzPEklIMrNMPj1cGg883Rh +8E6flC/wAHe8THH7onMi7ZZ0UJHbuiqwSRC/6aDlce4Vry8Isgoo3w21rUElyNb8Fe5 KduSQjSCQnHNuR3Y4Tbfp+cDqNwUOFHdRAuQz1MZUv+8gwZ0V+DkZDfGeFzs3nHBu/FD VqvrtJaAxRwz7GDVR8XstgWzZyJrlF9prfuRtfa0fg+Qwq70iQ7L9gtANubekJEHNLEv 4lQw== X-Gm-Message-State: ALoCoQkZ8iKwSSnzeyLt+FdLm5zu1a50jeRKM2AFhajp7LwXR5bQRCFSJCnTt299eskYyJXRav0v X-Received: by 10.58.221.197 with SMTP id qg5mr3345254vec.9.1395735994982; Tue, 25 Mar 2014 01:26:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.11 with SMTP id w11ls132846qgw.42.gmail; Tue, 25 Mar 2014 01:26:34 -0700 (PDT) X-Received: by 10.221.29.196 with SMTP id rz4mr54439801vcb.8.1395735994885; Tue, 25 Mar 2014 01:26:34 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id w1si3582214vet.119.2014.03.25.01.26.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:26:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so132467veb.4 for ; Tue, 25 Mar 2014 01:26:34 -0700 (PDT) X-Received: by 10.58.238.35 with SMTP id vh3mr53782927vec.16.1395735994800; Tue, 25 Mar 2014 01:26:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp285557vck; Tue, 25 Mar 2014 01:26:33 -0700 (PDT) X-Received: by 10.180.105.65 with SMTP id gk1mr21903372wib.12.1395735993254; Tue, 25 Mar 2014 01:26:33 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id ee7si2768692wic.49.2014.03.25.01.26.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2014 01:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMdj-0000hq-45; Tue, 25 Mar 2014 08:23:20 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMd7-0002Qm-Qg; Tue, 25 Mar 2014 08:22:41 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMbn-0002BQ-Mf for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2014 08:21:33 +0000 Received: by mail-wg0-f49.google.com with SMTP id a1so79891wgh.32 for ; Tue, 25 Mar 2014 01:20:57 -0700 (PDT) X-Received: by 10.181.13.40 with SMTP id ev8mr21675791wid.0.1395735657748; Tue, 25 Mar 2014 01:20:57 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id k4sm5567676wib.19.2014.03.25.01.20.56 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:20:57 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 21/47] mtd: nand: stm_nand_bch: provide shared BCH operations Date: Tue, 25 Mar 2014 08:19:38 +0000 Message-Id: <1395735604-26706-22-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> References: <1395735604-26706-1-git-send-email-lee.jones@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140325_042119_966465_DE013CCE X-CRM114-Status: GOOD ( 12.60 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: angus.clark@st.com, kernel@stlinux.com, lee.jones@linaro.org, linux-mtd@lists.infradead.org, pekon@ti.com, computersforpeace@gmail.com, dwmw2@infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Including one for programming the BCH sequence, taking care not to program two registers marked 'reserved' in the NANDi specification. Failing to take this precaution results in an imprecise data exception on ARM platforms. We also add an operation which waits on a completion timeout (released by the IRQ handler) and finally another which utilises the two aforementioned operations in order to erase a single block. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index fafde22..2042cdd 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -264,6 +264,61 @@ static void nandi_disable_interrupts(struct nandi_controller *nandi, } /* + * BCH Operations + */ +static inline void bch_load_prog_cpu(struct nandi_controller *nandi, + struct bch_prog *prog) +{ + uint32_t *src = (uint32_t *)prog; + uint32_t *dst = (uint32_t *)(nandi->base + NANDBCH_ADDRESS_REG_1); + int i; + + for (i = 0; i < 16; i++) { + /* Skip registers marked as "reserved" */ + if (i != 11 && i != 14) + writel(*src, dst); + dst++; + src++; + } +} + +static void bch_wait_seq(struct nandi_controller *nandi) +{ + int ret; + + ret = wait_for_completion_timeout(&nandi->seq_completed, HZ/2); + if (!ret) + dev_err(nandi->dev, "BCH Seq timeout\n"); +} + +static uint8_t bch_erase_block(struct nandi_controller *nandi, + loff_t offs) +{ + struct bch_prog *prog = &bch_prog_erase_block; + uint8_t status; + + dev_dbg(nandi->dev, "%s: offs = 0x%012llx\n", __func__, offs); + + prog->extra = (uint32_t)(offs >> nandi->page_shift); + + emiss_nandi_select(STM_NANDI_BCH); + + nandi_enable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + reinit_completion(&nandi->seq_completed); + + bch_load_prog_cpu(nandi, prog); + + bch_wait_seq(nandi); + + nandi_disable_interrupts(nandi, NANDBCH_INT_SEQNODESOVER); + + status = (uint8_t)(readl(nandi->base + + NANDBCH_CHECK_STATUS_REG_A) & 0xff); + + return status; +} + +/* * Initialisation */ static int bch_check_compatibility(struct nandi_controller *nandi,