Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3416219imm; Fri, 25 May 2018 05:28:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZonlSDJZ37pmYUyCHdEBXVAwASyHrwZLNmfnh738Ncx+fS5apmhaIOqPP3dSMsd6oVXLs/1 X-Received: by 2002:a62:4ec8:: with SMTP id c191-v6mr2330920pfb.153.1527251289534; Fri, 25 May 2018 05:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527251289; cv=none; d=google.com; s=arc-20160816; b=kCy/zpLkEdYNVwNwWpWcYmYTjw1tOsMVetRd9d9kaoY9BJF+ZNG4TzbL/S82QIy/pA eo0RU1JcI/w7z+xOzKKW1sj5/voDGoDn5g6k1adgy1hSUSGBw+A31QCmq3qroxLL8sZk C/mhgca4R/+ibe8K/ZgVNailByhix2X4mpcyiH78AM1fKZBskjMRpuwrEBuVCgX4UzYY Qs5qmGsMxrpSumQfNMQri3y3FwbDCyzflL1Vr/p2IheyALKBQ23xJtF8NecFreu44Vu+ N534VgZkFAqEzrN1ly7rIqB1NJXo/b1Wlyi8K8xKtyVqdPRnO2BxlzDwUjxZQnHoww/X 98Qg== 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=UalQN8VG+JNe//8NiqnHtDpQwtOGNOT5k4lukdpnNcQ=; b=SarxC3iLnD10/vaYIcqtHPupaD6AqMQx5MCR2Do4wAWbrQUBHPEYErn18Wz/Cf3big kk+g1hiMqx0p7E7g+ELm8jNl2wZoLY3Ozni7UAoiNHw084IFMhSqQBzsw8h2ZcieWXhi fzZ3fI/rcLxpFegcVHyjoGtsFc3hr4GgeZb02DDZUri3i9UZFUxAkUwx3dtNkaWIS3R3 BI3eQjsCwoTi/g5T0swMjzts4k76VVTPn51VfnkZUcD9wSCDZtLnJJzyebCvQkCwyQBn L+e6tP6uQ92OEF/dqiNUMdx6QBhpCqGtm18F02cAwyJdnB1rQKwbta9NoGs2kKxlNors Akiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=luNfBGss; dkim=pass header.i=@codeaurora.org header.s=default header.b=IQg5spx4; 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 w10-v6si23722424pfg.174.2018.05.25.05.27.54; Fri, 25 May 2018 05:28:09 -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=luNfBGss; dkim=pass header.i=@codeaurora.org header.s=default header.b=IQg5spx4; 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 S966785AbeEYMWG (ORCPT + 99 others); Fri, 25 May 2018 08:22:06 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:47044 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966747AbeEYMWD (ORCPT ); Fri, 25 May 2018 08:22:03 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B03DC60F78; Fri, 25 May 2018 12:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527250922; bh=YOmhHmHTaT0P+QR6bp2dQPx3nVE94X53uUEtVgmxAFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=luNfBGssH5nNfp3lq0ZO28+c+1AVaEz6gkGRze2OKrV+QqbJUQUV54mlER+F1XNXS 3MzDqJfUff1naswmiCnAsLITREKjbjwqXUIcPaKZjeW48JlFy0CdMHdKCVMC39LXGu tA60vud1xKzva5ASlTyVx7fwlWHjesvyNDHaSb6A= 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 E00F86076C; Fri, 25 May 2018 12:21:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527250921; bh=YOmhHmHTaT0P+QR6bp2dQPx3nVE94X53uUEtVgmxAFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQg5spx4i8FfRJPydzWG9TwmVwAJrIRG+ScJqMV11dGiELeoZG8vA4zKlcMZqeosD Gst698fLfSNsENl30lNjA99BMJT5okQinWMgfb1T67lH0jSEWwE/BLzS6NlfsmjVex MaadgvbB2lEpjUwOwU5aibuG39Sx2PzGcMstRGi4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E00F86076C 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 Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Cyrille Pitchen , Miquel Raynal , 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 v3 01/16] mtd: rawnand: helper function for setting up ECC configuration Date: Fri, 25 May 2018 17:51:29 +0530 Message-Id: <1527250904-21988-2-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527250904-21988-1-git-send-email-absahu@codeaurora.org> References: <1527250904-21988-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 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 | 42 ++++++++++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_base.c | 31 +++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 72f3a89..e52019d 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -6249,6 +6249,37 @@ 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) && + !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 5dad59b..89889fa 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1627,6 +1627,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