From patchwork Tue May 2 08:13:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Couzens X-Patchwork-Id: 98417 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp1759699qgf; Tue, 2 May 2017 01:14:42 -0700 (PDT) X-Received: by 10.98.150.78 with SMTP id c75mr30797696pfe.206.1493712881911; Tue, 02 May 2017 01:14:41 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id d16si9107475pli.110.2017.05.02.01.14.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2017 01:14:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To: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:List-Owner; bh=TciGn3r+BpXLgTvr4UBbctqMjGjw9Z/MuIDKcgK3AoE=; b=pXrV4SVN1lUy4CncbK1omEzC7U PNG2lpkEbiCoqx7ZatbcnHiQTRw+7sVq6fFBX3RU9cJ3UEptJeqkMfvulrJmWoD53WP3yUdhMW3t5 UKHwsFXLCtRruCXOWxy3qkUdVgrEpPWeCcSQnylG8Dl+ExnsbC8vrN8aSzXqBKGYLFLfmPDJNLmq8 DuPLqNzHrduCccPVNqVLwa0UsZ4cjC8eXL2WjWQj0NjMugYwDrwZEkZHJgLuGYEC4Y3ercpCBRR3k Re58sC3vHUhmppScTukLhAJqTNNe9OU9fvduyKOZIFlBtzkHhyPPmTxmJlxGstEfx6XgmBT3XIyLa BEQC5X0w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5Sx9-00065k-Rs; Tue, 02 May 2017 08:14:35 +0000 Received: from mail.base45.de ([2001:67c:2050:310::a:2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5Swc-0005Kb-5m for linux-mtd@lists.infradead.org; Tue, 02 May 2017 08:14:05 +0000 Received: from ip5b4049fd.dynamic.kabel-deutschland.de ([91.64.73.253] helo=lazus.yip) by mail.base45.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1d5SwC-0002Yz-11; Tue, 02 May 2017 10:13:36 +0200 From: Alexander Couzens To: linux-mtd@lists.infradead.org Subject: [PATCH 1/3][v2] mtd/nand: add ooblayout for old hamming layout Date: Tue, 2 May 2017 10:13:21 +0200 Message-Id: <20170502081323.3138-2-lynxis@fe80.eu> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170502081323.3138-1-lynxis@fe80.eu> References: <20170313074641.28b383e7@bbrezillon> <20170502081323.3138-1-lynxis@fe80.eu> In-Reply-To: <20170313074641.28b383e7@bbrezillon> References: <20170313074641.28b383e7@bbrezillon> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170502_011402_477226_9C5CA61C X-CRM114-Status: GOOD ( 14.50 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: Boris Brezillon , Alexander Couzens , Richard Weinberger MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org The old 1bit hamming layout requires the ecc data to be exact at predefined offsets. This can not changed because old installations would break. Signed-off-by: Alexander Couzens --- drivers/mtd/nand/nand_base.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/nand.h | 1 + 2 files changed, 72 insertions(+) -- 2.12.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index b0524f8accb6..daf3df157885 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -139,6 +139,77 @@ const struct mtd_ooblayout_ops nand_ooblayout_lp_ops = { }; EXPORT_SYMBOL_GPL(nand_ooblayout_lp_ops); +/* support the old large page layout for Hamming 1 bit where the ECC start at + * a defined offset. Should only used by old devices to compatible with old + * layout. Use nand_ooblayout_lp_ops if possible. + */ +static int nand_ooblayout_ecc_lp_hamming(struct mtd_info *mtd, int section, + struct mtd_oob_region *oobregion) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + struct nand_ecc_ctrl *ecc = &chip->ecc; + + if (section) + return -ERANGE; + + switch (mtd->oobsize) { + case 64: + oobregion->offset = 40; + break; + case 128: + oobregion->offset = 80; + break; + default: + return -ERANGE; + } + + oobregion->length = ecc->total; + if (oobregion->offset + oobregion->length > mtd->oobsize) + return -ERANGE; + + return 0; +} + +static int nand_ooblayout_free_lp_hamming(struct mtd_info *mtd, int section, + struct mtd_oob_region *oobregion) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + struct nand_ecc_ctrl *ecc = &chip->ecc; + int ecc_offset = 0; + + if (section < 0 || section > 1) + return -ERANGE; + + switch (mtd->oobsize) { + case 64: + ecc_offset = 40; + break; + case 128: + ecc_offset = 80; + break; + default: + return -ERANGE; + } + + if (section == 0) { + /* return the space before the ecc */ + oobregion->offset = 2; + oobregion->length = ecc_offset - 2; + } else { /* section == 1 */ + /* return free space after ecc */ + oobregion->offset = ecc_offset + ecc->total; + oobregion->length = mtd->oobsize - oobregion->offset; + } + + return 0; +} + +const struct mtd_ooblayout_ops nand_ooblayout_lp_hamming_ops = { + .ecc = nand_ooblayout_ecc_lp_hamming, + .free = nand_ooblayout_free_lp_hamming, +}; +EXPORT_SYMBOL_GPL(nand_ooblayout_lp_hamming_ops); + static int check_offs_len(struct mtd_info *mtd, loff_t ofs, uint64_t len) { diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 9591e0fbe5bd..da33933950a5 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -914,6 +914,7 @@ struct nand_chip { extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops; extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops; +extern const struct mtd_ooblayout_ops nand_ooblayout_lp_hamming_ops; static inline void nand_set_flash_node(struct nand_chip *chip, struct device_node *np)