Received: by 10.223.185.116 with SMTP id b49csp1894421wrg; Sun, 4 Mar 2018 12:34:40 -0800 (PST) X-Google-Smtp-Source: AG47ELvHF1EjLloauLtr52Xt4U+iF0cGnGQsWg0hW1N9VuHI26vDM4sllngy4jkWw/f0xoUgNufx X-Received: by 10.101.74.10 with SMTP id s10mr10630302pgq.219.1520195680484; Sun, 04 Mar 2018 12:34:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520195680; cv=none; d=google.com; s=arc-20160816; b=pcRKh+WiEMTS5D+um52vSsZpiIMUfFTsYXuJ3pP2xib+v+YhN+wU+vHx6Rpvjmdg3c Ee+fM4rCAlAEW5xJQ0pqvv38QEFcSt8xdB+wX20GtRqrJkMnjDoMLpGruXdCdz/wPwtk FcrzgDyev5Q3aScf6s0e0RmCTiTKwesrzeYzOykNFIFfcguIVLteS/e2eun5sXD2nPYV QbQuub9KKNZAa/xOCKJHEiGpGgD5ggKZ4dbFlR8U1/zhJfZBnWF5GhXP4IwiY2YWOSPU plaB2KqnsTiLt9KHS6s+D7en2buWUdiQkFrm5DjNcBk3rQyOMQfrNdHeUj/gtVyxeLs/ xLng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rP1jJb/xhg5gUMaMKU0KxRA5ZNdBrubBekiiig0d6Fk=; b=ClGUgwYDMM5RgEi5sfaaWw1V5yKN3XgcOUszR5BuWJapK7iYkQdwXxLDMW9EuC6lAb czyYsQtU0VfAKv9OILCI4eqVa9tTnVAhw6oJ12v4mz6oNuStfYbOtrbDd39QOxG508FZ RYijYU7J/6wwCF/+Y0fcdm5ODfnedCGU3CGJm/IFEhXu4yyQisvge14GZ/VLxqSiebaf Ab2ciBBrNtgdyWcSopMmdIa4vDJvZqqmdA9iAIlpikR27Oyl4gdS3+c6wbxf/0Y/w6yj sXml+GXuV3vnhr+6+G0/mhpTfo4oH62Wpsk8XBGisyYAwEUZvpJ9a5kana2A3r3eMFyB 44VA== ARC-Authentication-Results: i=1; mx.google.com; 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 92-v6si2174333plw.562.2018.03.04.12.34.26; Sun, 04 Mar 2018 12:34:40 -0800 (PST) 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; 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 S1752054AbeCDUGJ (ORCPT + 99 others); Sun, 4 Mar 2018 15:06:09 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:55756 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751818AbeCDUGH (ORCPT ); Sun, 4 Mar 2018 15:06:07 -0500 Received: from trochilidae.lan (unknown [IPv6:2001:1620:c6e::127]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 214215C0256; Sun, 4 Mar 2018 21:06:05 +0100 (CET) From: Stefan Agner To: han.xu@nxp.com, boris.brezillon@free-electrons.com Cc: marek.vasut@gmail.com, richard@nod.at, dwmw2@infradead.org, cyrille.pitchen@wedev4u.fr, max.oss.09@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Stefan Agner Subject: [PATCH v2 1/2] mtd: rawnand: gpmi: add support for specific ECC strength Date: Sun, 4 Mar 2018 21:06:01 +0100 Message-Id: <20180304200602.11475-1-stefan@agner.ch> X-Mailer: git-send-email 2.16.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for specified ECC strength/size using device tree properties nand-ecc-strength/nand-ecc-step-size. Signed-off-by: Stefan Agner --- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index 61fdd733492f..d04754289c03 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -198,17 +198,16 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this) * * We may have available oob space in this case. */ -static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) +static int set_geometry_by_ecc_info(struct gpmi_nand_data *this, + unsigned int ecc_strength, + unsigned int ecc_step) { struct bch_geometry *geo = &this->bch_geometry; struct nand_chip *chip = &this->nand; struct mtd_info *mtd = nand_to_mtd(chip); unsigned int block_mark_bit_offset; - if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) - return -EINVAL; - - switch (chip->ecc_step_ds) { + switch (ecc_step) { case SZ_512: geo->gf_len = 13; break; @@ -221,8 +220,8 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) chip->ecc_strength_ds, chip->ecc_step_ds); return -EINVAL; } - geo->ecc_chunk_size = chip->ecc_step_ds; - geo->ecc_strength = round_up(chip->ecc_strength_ds, 2); + geo->ecc_chunk_size = ecc_step; + geo->ecc_strength = round_up(ecc_strength, 2); if (!gpmi_check_ecc(this)) return -EINVAL; @@ -230,7 +229,7 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this) if (geo->ecc_chunk_size < mtd->oobsize) { dev_err(this->dev, "unsupported nand chip. ecc size: %d, oob size : %d\n", - chip->ecc_step_ds, mtd->oobsize); + ecc_step, mtd->oobsize); return -EINVAL; } @@ -423,9 +422,20 @@ static int legacy_set_geometry(struct gpmi_nand_data *this) int common_nfc_set_geometry(struct gpmi_nand_data *this) { + struct nand_chip *chip = &this->nand; + + if (chip->ecc.strength > 0 && chip->ecc.size > 0) + return set_geometry_by_ecc_info(this, chip->ecc.strength, + chip->ecc.size); + if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) - || legacy_set_geometry(this)) - return set_geometry_by_ecc_info(this); + || legacy_set_geometry(this)) { + if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) + return -EINVAL; + + return set_geometry_by_ecc_info(this, chip->ecc_strength_ds, + chip->ecc_step_ds); + } return 0; } -- 2.16.2