From patchwork Thu May 1 09:56:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29461 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 41C84203F3 for ; Thu, 1 May 2014 09:57:45 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id hr9sf9612765vcb.3 for ; Thu, 01 May 2014 02:57:45 -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=VacEPZeLqt4VcB4k7YthhhW85miKV55Lv6ocw6RpmI8=; b=ZfcRjTgjNf01h1N4CutfydB3ro6jW4aBCL4wLeUDC7cS9sRE3FvY5jOHRMLT/H7pvX lOKvL4f/tEkO7xuieGjBHTYRMM+EV6B7ZFwrLS2XIoPMbfbrh8jdDda5h9h3l//culcB sX2sOsM8MQoZY7q/5GbdJKNZDt+iob4hKBgd8r5o3MmBF6ZKyxenk+4YDH391bMKqE2K 3tXYWZZH1md7v0ZxTcD7o7tbiEAtyQ+rznZFgPIa7sdiNWygHtgTeTtfPnD17Bs255Dm Ou0Cr9ju45iVjdCyYCXPPahGlrzC9pofozadZY0pag6j9wD9azWQy7yZAhXO4ua5aeWQ gZmg== X-Gm-Message-State: ALoCoQn2dnVRsBPnhUZQ6k2UHdWre9bkrD3cHUOLo3iz50I6sGmFvlf8YWj83kfQdITJjc86IR0M X-Received: by 10.52.146.45 with SMTP id sz13mr4507124vdb.6.1398938265006; Thu, 01 May 2014 02:57:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.51 with SMTP id w48ls1009743qgd.6.gmail; Thu, 01 May 2014 02:57:44 -0700 (PDT) X-Received: by 10.58.13.104 with SMTP id g8mr8163230vec.16.1398938264947; Thu, 01 May 2014 02:57:44 -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 jb7si5964383vec.35.2014.05.01.02.57.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:44 -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.128.173; Received: by mail-ve0-f173.google.com with SMTP id pa12so2682349veb.32 for ; Thu, 01 May 2014 02:57:44 -0700 (PDT) X-Received: by 10.58.107.65 with SMTP id ha1mr8340939veb.1.1398938264887; Thu, 01 May 2014 02:57:44 -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 ib8csp12922vcb; Thu, 1 May 2014 02:57:44 -0700 (PDT) X-Received: by 10.180.107.5 with SMTP id gy5mr1529052wib.44.1398938264017; Thu, 01 May 2014 02:57:44 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by mx.google.com with ESMTPS id fj4si573063wib.66.2014.05.01.02.57.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:44 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=209.85.212.177; Received: by mail-wi0-f177.google.com with SMTP id cc10so402942wib.16 for ; Thu, 01 May 2014 02:57:43 -0700 (PDT) X-Received: by 10.180.14.199 with SMTP id r7mr1592320wic.0.1398938263504; Thu, 01 May 2014 02:57:43 -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.41 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:42 -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 18/47] mtd: nand: stm_nand_bch: automatically set EEC mode if requested Date: Thu, 1 May 2014 10:56:25 +0100 Message-Id: <1398938214-17847-19-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: , Here we automatically select the strongest ECC scheme compatible with the size of the OOB. Signed-off-by: Lee Jones --- drivers/mtd/nand/stm_nand_bch.c | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c index 8302273..31864e5 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -32,6 +32,13 @@ /* NANDi BCH Controller properties */ #define NANDI_BCH_SECTOR_SIZE 1024 +/* BCH ECC sizes */ +static int bch_ecc_sizes[] = { + [BCH_18BIT_ECC] = 32, + [BCH_30BIT_ECC] = 54, + [BCH_NO_ECC] = 0, +}; + /* Bad Block Table (BBT) */ struct nandi_bbt_info { uint32_t bbt_size; /* Size of bad-block table */ @@ -302,6 +309,25 @@ static void nandi_disable_interrupts(struct nandi_controller *nandi, writel(val, nandi->base + NANDBCH_INT_EN); } +/* Select strongest ECC scheme compatible with OOB size */ +static int bch_set_ecc_auto(struct nandi_controller *nandi, + struct mtd_info *mtd) +{ + int oob_bytes_per_sector = mtd->oobsize / nandi->sectors_per_page; + int try_ecc_modes[] = { BCH_30BIT_ECC, BCH_18BIT_ECC, -1 }; + int m, ecc_mode; + + for (m = 0; try_ecc_modes[m] >= 0; m++) { + ecc_mode = try_ecc_modes[m]; + if (oob_bytes_per_sector >= bch_ecc_sizes[ecc_mode]) { + nandi->bch_ecc_mode = ecc_mode; + return 0; + } + } + + return -EINVAL; +} + static void nandi_set_mtd_defaults(struct nandi_controller *nandi, struct mtd_info *mtd, struct nand_chip *chip) { @@ -939,6 +965,23 @@ static int stm_nand_bch_probe(struct platform_device *pdev) 0x10000) ? true : false; mtd->writebufsize = mtd->writesize; + /* Set ECC mode */ + if (pdata->bch_ecc_cfg == BCH_ECC_AUTO) { + err = bch_set_ecc_auto(nandi, mtd); + if (err) { + dev_err(nandi->dev, "insufficient OOB for BCH ECC\n"); + return err; + } + } else { + nandi->bch_ecc_mode = pdata->bch_ecc_cfg; + } + + chip->ecc.size = NANDI_BCH_SECTOR_SIZE; + chip->ecc.bytes = mtd->oobsize; + + info->ecclayout.eccbytes = + nandi->sectors_per_page * bch_ecc_sizes[nandi->bch_ecc_mode]; + return 0; }