Received: by 10.192.165.148 with SMTP id m20csp1781854imm; Thu, 3 May 2018 05:26:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpZee3Z5Ti7aphIdTRFSDrokA5y6r6mMYuXl7119chMfF4DHK/wpjaZbkrJbFZjChDLbuGI X-Received: by 2002:a17:902:6b45:: with SMTP id g5-v6mr9224282plt.67.1525350402472; Thu, 03 May 2018 05:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525350402; cv=none; d=google.com; s=arc-20160816; b=f3AlAN7V4Ae82TUw4B/pxUvC/RusLK8GheUWoNE5ymJ0WDzbPsQWDqkMRuWGIC1ov6 aW8DDF6uo9SarfHT+QGIJgF3IWzLB00I4s1ojA42DHH/SFk4mW/cqo/6KPl4iqXguUKB DKIeIar/mIYomEXDWjk44sLip3ojVU5Ywwz0PDmS2xQF/BBjZWx/yiw+R8rVakk885WS EtdKEOIUKhSnDCwMNal7IIDBSpLmnhQyg3DfVyAUL3Z9c9x84hojg5XdOH42+RQtcHon HPvTAHRCq4W/KlUXbH4w3IGbToRJBVrllWtmWRWAwu+2YN4+IdYZ8b4zJZb0PZx8W+Cd j6hA== 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=TToo8zQo8zBdhyQZjygweMu3ktPGvqEKnIk0R07vYzk=; b=S034L8qQN8Oj+jQ23ZQ77lRHzkEq4nnhP+aDzhyyUcQD9a7V75PSs0630kwoXCoCOp lMn4ELmIdNoomHFSUEGP5qu1kcOY5XjiKuschR4dH1IBY/eo69QfEdDraU6f/GeZNqSb Yh1GqbnmSHyOI6YFwsPOxvWn3PK9VDUNQKvJvx59WERXoor0LVsqhzmRDIVYvp3STopC CL6v5eJ8qH4aJVohpMBsca3tTmX0+fO0PJwAEMFcCgCMLLnKNToIhNTw52AVKw6ivvNJ R8UTVISGGu3XuwAbGWShzkSF919RKYrykUsM2sBCEiwhkYWLml4c8tPxrK9aF3a/NQYT z9Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=hrEUafBB; dkim=pass header.i=@codeaurora.org header.s=default header.b=CdWqYQd5; 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 c129si13305088pfc.367.2018.05.03.05.26.28; Thu, 03 May 2018 05:26:42 -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=hrEUafBB; dkim=pass header.i=@codeaurora.org header.s=default header.b=CdWqYQd5; 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 S1751869AbeECMVH (ORCPT + 99 others); Thu, 3 May 2018 08:21:07 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:41056 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbeECMU7 (ORCPT ); Thu, 3 May 2018 08:20:59 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 71F93607F5; Thu, 3 May 2018 12:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525350058; bh=OLn2vmhLI9kHY71C122glWwvE7YVKOX3BJF/iapx3Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hrEUafBB40dtJt1qDx9gDxuaHEN2jDu/bWEab6ecDErI1gtFhs//dzsE6qWc/VhpM 5G+j4Ner9ihdq1zcbbHrMIY5kbgBoRBDQGOLa+g67OB9S1GBtZuQEKkBIzZfGW9cx3 VSIUB71JM9Y1OJ9U7dfvPSV4Ui7evov/pD1gc6Zg= 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 A2D8A607CF; Thu, 3 May 2018 12:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525350056; bh=OLn2vmhLI9kHY71C122glWwvE7YVKOX3BJF/iapx3Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdWqYQd5WG6JIhaRyeVEDYrMo8MqGfjidwPGoEF7XaDNbojhoug5qCJ0rn2B/YQGl Q4GQIOu2bbftDMXL8PuI0rPqDqXQvxCtNT30grduq3K+wQmYtknY6xw0V6HWpIPMt/ Q6ckYTkpne8yXoCA5wbC+rAZivkI2ppMUz7w8mm8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A2D8A607CF 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 , 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 v2 01/14] mtd: rawnand: helper function for setting up ECC parameters Date: Thu, 3 May 2018 17:50:28 +0530 Message-Id: <1525350041-22995-2-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525350041-22995-1-git-send-email-absahu@codeaurora.org> References: <1525350041-22995-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 with warning. This patch introduces nand_ecc_param_setup 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 v1: NEW PATCH drivers/mtd/nand/raw/nand_base.c | 42 ++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 72f3a89..dd7a984 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -6249,6 +6249,48 @@ int nand_maximize_ecc(struct nand_chip *chip, } EXPORT_SYMBOL_GPL(nand_maximize_ecc); +/** + * nand_ecc_param_setup - 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 strength 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 + * and print the warning. + * + * On success, the chosen ECC settings are set. + */ +int nand_ecc_param_setup(struct nand_chip *chip, + const struct nand_ecc_caps *caps, int oobavail) +{ + int ret; + + 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; + + ret = nand_maximize_ecc(chip, caps, oobavail); + if (!ret) + pr_warn("ECC (step, strength) = (%d, %d) not supported on this controller. Fallback to (%d, %d)\n", + chip->ecc_step_ds, chip->ecc_strength_ds, + chip->ecc.size, chip->ecc.strength); + + return ret; +} +EXPORT_SYMBOL_GPL(nand_ecc_param_setup); + /* * 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..afc7447 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_param_setup(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