From patchwork Tue Mar 25 08:19:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 26984 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1CF0220062 for ; Tue, 25 Mar 2014 08:23:30 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id oz11sf289614veb.9 for ; Tue, 25 Mar 2014 01:23:29 -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=eoyXrnniX3YKovpHjSAgE47AG2GQDcn92do0wWadj/Y=; b=Pk4qvbbhfYmKSnZrOKZ8YkDpV99O/2iOTwMMZv2DwuxTmVQPOICDY0vreZRoRrs4Qx QfgG5lQXG+q1iwSvOna1q+yhsM8WWLvk/7ebbaYrUoxcxcaQX6e5gStNyowtIH15jBZS bPxWAIhBbXSTom0xxkwaZ0uR+84QsGHGnX+Xxg99VDsmNUQ/UUBu+cJfSB9cjEeGl6IO QWhMYOyQuckPyEa6lqPks62wgt5WosTyFm896fRCfAhUAP8Je06SVwdIjb44inR9r/bR X1Zv3ySDCvLaAWLk6A9ljk/lfQUC+UcUFjbjN77Kyb+YsyrGlf9Z5xFNSyOuyZBLiC9A q58w== X-Gm-Message-State: ALoCoQnKmD8r5yQ2n7VU4e3xusJj4cg58pLmZc5NywVMZww0EOc3Vyup0VryM4F3PgZ3cbHp94iX X-Received: by 10.58.199.170 with SMTP id jl10mr4715807vec.1.1395735809878; Tue, 25 Mar 2014 01:23:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.72 with SMTP id l66ls129692qge.16.gmail; Tue, 25 Mar 2014 01:23:29 -0700 (PDT) X-Received: by 10.52.18.70 with SMTP id u6mr46922864vdd.11.1395735809792; Tue, 25 Mar 2014 01:23:29 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id f7si3533088vcz.165.2014.03.25.01.23.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:23:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id ik5so134500vcb.14 for ; Tue, 25 Mar 2014 01:23:29 -0700 (PDT) X-Received: by 10.52.6.162 with SMTP id c2mr12876407vda.6.1395735809696; Tue, 25 Mar 2014 01:23:29 -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 i9csp285412vck; Tue, 25 Mar 2014 01:23:28 -0700 (PDT) X-Received: by 10.180.73.1 with SMTP id h1mr21774774wiv.10.1395735807983; Tue, 25 Mar 2014 01:23:27 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id de3si11637573wib.7.2014.03.25.01.23.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Mar 2014 01:23:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mtd-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 1WSMcx-0000Dk-PW; Tue, 25 Mar 2014 08:22:32 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMcV-0002Mo-Fy; Tue, 25 Mar 2014 08:22:03 +0000 Received: from mail-wi0-f172.google.com ([209.85.212.172]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WSMbi-0002Ay-KD for linux-mtd@lists.infradead.org; Tue, 25 Mar 2014 08:21:27 +0000 Received: by mail-wi0-f172.google.com with SMTP id hi5so3184190wib.5 for ; Tue, 25 Mar 2014 01:20:52 -0700 (PDT) X-Received: by 10.180.97.37 with SMTP id dx5mr19868987wib.53.1395735652148; Tue, 25 Mar 2014 01:20:52 -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.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 01:20:51 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC 18/47] mtd: nand: stm_nand_bch: ensure configuration is compatible with this driver Date: Tue, 25 Mar 2014 08:19:35 +0000 Message-Id: <1395735604-26706-19-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_042114_843624_35AF78E4 X-CRM114-Status: GOOD ( 13.02 ) 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 [209.85.212.172 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-mtd@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-mtd" Errors-To: linux-mtd-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.220.169 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 Some chip characteristics have known incompatibilities with the function of this driver. Here we check for this characteristics and refuse to run if they are present. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 60a7800..365a73b 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -142,6 +142,36 @@ static void nandi_disable_interrupts(struct nandi_controller *nandi, writel(val, nandi->base + NANDBCH_INT_EN); } +/* + * Initialisation + */ +static int bch_check_compatibility(struct nandi_controller *nandi, + struct mtd_info *mtd, + struct nand_chip *chip) +{ + if (chip->bits_per_cell > 1) + dev_warn(nandi->dev, "MLC NAND not fully supported\n"); + + if (chip->options & NAND_BUSWIDTH_16) { + dev_err(nandi->dev, "x16 NAND not supported\n"); + return false; + } + + if (nandi->blocks_per_device / 4 > mtd->writesize) { + /* Need to implement multi-page BBT support... */ + dev_err(nandi->dev, "BBT too big to fit in single page\n"); + return false; + } + + if (bch_ecc_sizes[nandi->bch_ecc_mode] * nandi->sectors_per_page > + mtd->oobsize) { + dev_err(nandi->dev, "insufficient OOB for selected ECC\n"); + return false; + } + + return true; +} + /* Select strongest ECC scheme compatible with OOB size */ static int bch_set_ecc_auto(struct nandi_controller *nandi, struct mtd_info *mtd) @@ -737,7 +767,7 @@ static int stm_nand_bch_probe(struct platform_device *pdev) struct nandi_info *info; struct nand_chip *chip; struct mtd_info *mtd; - int err; + int compatible, err; if (!pdata) { if (!np) { @@ -832,6 +862,13 @@ static int stm_nand_bch_probe(struct platform_device *pdev) info->ecclayout.eccbytes = nandi->sectors_per_page * bch_ecc_sizes[nandi->bch_ecc_mode]; + compatible = bch_check_compatibility(nandi, mtd, chip); + if (!compatible) { + dev_err(nandi->dev, + "NAND device incompatible with NANDi/BCH Controller\n"); + return -EINVAL; + } + return 0; }