From patchwork Thu May 1 09:56:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29462 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AB3DE203F3 for ; Thu, 1 May 2014 09:57:46 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id x3sf4854298qcv.10 for ; Thu, 01 May 2014 02:57:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=ze2TORCVGlcbYnpY6ca0HT1DItRSvjUOPwlGPXVu9gU=; b=e+dBKTeMUKWeRXszhEvcxIypsrv9SdI1NQPdWc479kyMqCaZQ2vsU5WIXFl+GkbcPJ lWDWnRHm4hfJLScjor2do7UNn4HuC1AobsK7aFbk+fO4oze/OZ11CvfomRLWPoJglo2E ojP82sPhXn6a/zHp7pCMK+TG8Noim65NZY9etmm7ae8zRBWRw9jA1aZx0VNOKDmhwbSA LeKCjtshPUnLRrzGrI8NwWJebrcYSj+NmjtrscbxI+fO4brEO24Kj81ap84mXVgHcF2S a8lJgmEsBHpBcA0O2uWFhzfBGDo7pFhy1y21OnWT/QEQj97W7/h26qqr0vO3zgeCP5fK 2eCg== X-Gm-Message-State: ALoCoQlZngUAWRGXsC6LZ6/VXwpUPwRwKNNqdwAXJigdGOn3WEamrEO67SSSDtAxv6ZP32+IiH9G X-Received: by 10.58.82.193 with SMTP id k1mr828861vey.41.1398938266486; Thu, 01 May 2014 02:57:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.229 with SMTP id o92ls994511qge.95.gmail; Thu, 01 May 2014 02:57:46 -0700 (PDT) X-Received: by 10.220.163.3 with SMTP id y3mr8156912vcx.7.1398938266379; Thu, 01 May 2014 02:57:46 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id ya4si5973107vec.55.2014.05.01.02.57.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:46 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id ld13so3749151vcb.30 for ; Thu, 01 May 2014 02:57:46 -0700 (PDT) X-Received: by 10.58.74.38 with SMTP id q6mr8019765vev.7.1398938266301; Thu, 01 May 2014 02:57:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12924vcb; Thu, 1 May 2014 02:57:45 -0700 (PDT) X-Received: by 10.194.92.177 with SMTP id cn17mr8261692wjb.18.1398938265718; Thu, 01 May 2014 02:57:45 -0700 (PDT) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by mx.google.com with ESMTPS id hc7si584110wib.2.2014.05.01.02.57.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:45 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.171; Received: by mail-wi0-f171.google.com with SMTP id hm4so408471wib.10 for ; Thu, 01 May 2014 02:57:45 -0700 (PDT) X-Received: by 10.194.60.4 with SMTP id d4mr8278909wjr.28.1398938265313; Thu, 01 May 2014 02:57:45 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.57.43 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:44 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones Subject: [PATCH 19/47] mtd: nand: stm_nand_bch: ensure configuration is compatible with this driver Date: Thu, 1 May 2014 10:56:26 +0100 Message-Id: <1398938214-17847-20-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 31864e5..66ff99d 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -309,6 +309,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) @@ -886,7 +916,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 (!np) { dev_err(&pdev->dev, "DT node found\n"); @@ -982,6 +1012,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; }