Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp509046imm; Wed, 20 Jun 2018 01:56:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ345Ql+044LI1Q1CGHS4X3kjBSgWxoUnHr5Pn64qBc7ABL9H3UswRbUq+lbAOp9PlKmjEQ X-Received: by 2002:a63:7781:: with SMTP id s123-v6mr18200079pgc.117.1529484993642; Wed, 20 Jun 2018 01:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529484993; cv=none; d=google.com; s=arc-20160816; b=iS7SajV9pw52L1TXb/udMSrl1x9Ss2ImQEN0+FHAAS2EUB8GGmjLXd99HlzELUxPu1 tdRD1Rb/+HoNftSz/5wcgyboXw5WLNSHdPspxoj63hlsB+KyhYYaNSyams0edy8sn8Z1 kl6n5pVGaG8Vqf7BJCSOtGCim6CLCpS4tSY9c7y6YFtcgNV18NOFc85kM1tt2tUKVHzH 1oB4CYHMXgCHSke6KoMLgWz0v9Ke/buRo9zkKBW8rdzFIiSiE791oaDfyk+knExUlvNh soGi+qJL0mV+eWdYeu2URvfSMkEOANAXnGqLpLvQl1qOqRE6+b9nsjyGK3RLU4VsvfSF fsxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=cBQavPooEqE6fv3Uj0uploAliIxZfXqQ+m/4vJCs0VI=; b=UXs1e/7CbVFwAyYeaYC93hWelE5seiqkKnMLzTaBzQQswjz3fdqZ3GcyTKmrsOi2+J eeWUfOdQr/XQ2ZXZ6AdHUReS42eztDfo5rO3L09STldejxG0HAKvrQjfpWFiXdoiJ8vk ra3Q9F4xo6yACH80EsX4C2mlCNojJbBe1c1xZu2zbkYPG0jTGi8lDpUxKaCu8wUcl2ne 7+yf4sst9DSAnKtLdPLbM1vQNqiUeeozkfslT0rhczC/7D8lMbNru2/Kb/hyIxmKq5qI YxSo1MQ+2zGMnBlAg9RVI7ROwLGPlJ6ci3epZXUw6CVEP+9ESr2C5BgPpABEvQTQeGqD Ix5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="QK6/c9DG"; dkim=pass header.i=@codeaurora.org header.s=default header.b="Uja/17Qm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si1905857plo.363.2018.06.20.01.56.19; Wed, 20 Jun 2018 01:56:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="QK6/c9DG"; dkim=pass header.i=@codeaurora.org header.s=default header.b="Uja/17Qm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932699AbeFTIwS (ORCPT + 99 others); Wed, 20 Jun 2018 04:52:18 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:49634 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753906AbeFTIpE (ORCPT ); Wed, 20 Jun 2018 04:45:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9BBFA60B10; Wed, 20 Jun 2018 07:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529479677; bh=GEjbLk+ZDg0Uh7Dn0hTtktdHgbTWSSeEmQiP0fuJweQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QK6/c9DGb44pNmr75cEK21hFFn7crlAC0HOInOyfMXuvtddQJbORwSU70PP4TV+9z Z5HT7/j/n6AyXMVnOs5tT2rwUj/GHwlNOXHvwPAjwLfS/afCYg7LAc1AA+35OFvzKp IR3Skq5curI26dEVs8Gt8S120oTqsrRhYiEs7qw4= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from absahu-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: absahu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4102560B11; Wed, 20 Jun 2018 07:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529479676; bh=GEjbLk+ZDg0Uh7Dn0hTtktdHgbTWSSeEmQiP0fuJweQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uja/17QmEp4G78lpbTNk6uAQ9PuWfz7u00u4U79Bq6Fxbqc+RdKUd/U1m3Ji2pfYN 7k8I0gdiJEsh6saACo75HILzLUKAA+2swihSMkyTbIfQzVlK5pvVJLKjBOwgiDiZS5 SuwroZHLKfK5aF+iyAXe3ZLhKQ7eY6fuMW2oeQOI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4102560B11 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=absahu@codeaurora.org From: Abhishek Sahu To: Boris Brezillon , Miquel Raynal Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Andy Gross , Archit Taneja , Abhishek Sahu , Masahiro Yamada Subject: [PATCH v4 01/15] mtd: rawnand: helper function for setting up ECC configuration Date: Wed, 20 Jun 2018 12:57:28 +0530 Message-Id: <1529479662-4026-2-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529479662-4026-1-git-send-email-absahu@codeaurora.org> References: <1529479662-4026-1-git-send-email-absahu@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit 2c8f8afa7f92 ("mtd: nand: add generic helpers to check, match, maximize ECC settings") provides generic helpers which drivers can use for setting up ECC parameters. Since same board can have different ECC strength nand chips so following is the logic for setting up ECC strength and ECC step size, which can be used by most of the drivers. 1. If both ECC step size and ECC strength are already set (usually by DT) then just check whether this setting is supported by NAND controller. 2. If NAND_ECC_MAXIMIZE is set, then select maximum ECC strength supported by NAND controller. 3. Otherwise, try to match the ECC step size and ECC strength closest to the chip's requirement. If available OOB size can't fit the chip requirement then select maximum ECC strength which can be fit with available OOB size. This patch introduces nand_ecc_choose_conf function which calls the required helper functions for the above logic. The drivers can use this single function instead of calling the 3 helper functions individually. CC: Masahiro Yamada Signed-off-by: Abhishek Sahu --- * Changes from v3: 1. call nand_maximize_ecc() 2 times to make code more clear. * Changes from v2: 1. Renamed function to nand_ecc_choose_conf. 2. Minor code reorganization to remove warning and 2 function calls for nand_maximize_ecc. * Changes from v1: NEW PATCH drivers/mtd/nand/raw/nand_base.c | 33 +++++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 10c4f991..c64e3fc 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -6287,6 +6287,39 @@ int nand_maximize_ecc(struct nand_chip *chip, } EXPORT_SYMBOL_GPL(nand_maximize_ecc); +/** + * nand_ecc_choose_conf - Set the ECC strength and ECC step size + * @chip: nand chip info structure + * @caps: ECC engine caps info structure + * @oobavail: OOB size that the ECC engine can use + * + * Choose the ECC configuration according to following logic + * + * 1. If both ECC step size and ECC strength are already set (usually by DT) + * then check if it is supported by this controller. + * 2. If NAND_ECC_MAXIMIZE is set, then select maximum ECC strength. + * 3. Otherwise, try to match the ECC step size and ECC strength closest + * to the chip's requirement. If available OOB size can't fit the chip + * requirement then fallback to the maximum ECC step size and ECC strength. + * + * On success, the chosen ECC settings are set. + */ +int nand_ecc_choose_conf(struct nand_chip *chip, + const struct nand_ecc_caps *caps, int oobavail) +{ + if (chip->ecc.size && chip->ecc.strength) + return nand_check_ecc_caps(chip, caps, oobavail); + + if (chip->ecc.options & NAND_ECC_MAXIMIZE) + return nand_maximize_ecc(chip, caps, oobavail); + + if (!nand_match_ecc_req(chip, caps, oobavail)) + return 0; + + return nand_maximize_ecc(chip, caps, oobavail); +} +EXPORT_SYMBOL_GPL(nand_ecc_choose_conf); + /* * Check if the chip configuration meet the datasheet requirements. diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 3e8ec3b..03a0061 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1650,6 +1650,9 @@ int nand_match_ecc_req(struct nand_chip *chip, int nand_maximize_ecc(struct nand_chip *chip, const struct nand_ecc_caps *caps, int oobavail); +int nand_ecc_choose_conf(struct nand_chip *chip, + const struct nand_ecc_caps *caps, int oobavail); + /* Default write_oob implementation */ int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation