Received: by 10.223.176.5 with SMTP id f5csp934036wra; Tue, 6 Feb 2018 09:42:55 -0800 (PST) X-Google-Smtp-Source: AH8x224neAIoepRRjMwUTsUkpCHxXu5o/S06/VmTkHwajte5HeVKxSbybpiltu2jz5P+6W0fAsy6 X-Received: by 2002:a17:902:5305:: with SMTP id b5-v6mr3073519pli.61.1517938975134; Tue, 06 Feb 2018 09:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517938975; cv=none; d=google.com; s=arc-20160816; b=wt1TYhj2H4KbJauV1sckG8tWux3Khv00rgvy0uvPC7STBYXsXt/IiihO77KGE4CrYO 0iIkzbniw11y676jK8Z29y9RK9Ws3vOCtFtVYI5R0JIBaXKzYfIGFc1W9GSQhiQK3yK4 FuoxAPjghAPIClMPMlBAXHsp/gjGv9jF6b1bcsZLDadQmVcauLUAcrSe9XNq5gLKd+NW rXwpZ+4BrRb4zQwLtovz69qAWvd4jKGoHbU1YTIiHlK5IQR7Fpt/kN9P3wC3oxjzevII T6+r5Of+h2wxq1VTQfB3Ga0MAXY/hAdk+vup87dSNcINloXrC7+Z8IqAh7FxLbdj1x+p vNEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=jVR8ZfyK4qgib9P/qUSr3SD/blggnmH/1LR1xIFYDsA=; b=qfqg7IN21UU9YefpQwjCiBMWNM9cvRxPmA9wVgRQvnrAaDuX1UG/sUctTN5JZHJA3K nYx6f0CJU1OKNEXqYnp3ed7zMsnrZjLYEEJHnq7zRw1KiuKM2QQFhM7O6s4u0pFZollq GKC+VKkPBgsVwOYwm2N1g7fbYbVHKfMHC07WrmVK6udOaeEYFpbif14gi6gUbIUbfwq3 j4N2YPXNJsqfdXpMuNA5hYOpk3wiyOF6iTdjLLSq4x05Vamc0uBEWoqKiB3mHT7k9mZ6 G6ZSrPnzBL8NbCActZBczy56aoLy+3NenoLKLlvnclOTaXKxxJf3tCsL+b2eai7ztxJI F1FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=pb80a+HC; 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 d67si1653373pfl.105.2018.02.06.09.42.41; Tue, 06 Feb 2018 09:42:55 -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; dkim=pass header.i=@agner.ch header.s=dkim header.b=pb80a+HC; 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 S1752726AbeBFRkk (ORCPT + 99 others); Tue, 6 Feb 2018 12:40:40 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:33765 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752468AbeBFRk0 (ORCPT ); Tue, 6 Feb 2018 12:40:26 -0500 Received: from trochilidae.toradex.int (unknown [46.140.72.82]) by mail.kmu-office.ch (Postfix) with ESMTPSA id D794D5C0EFE; Tue, 6 Feb 2018 18:33:02 +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 2/2] mtd: nand: gpmi: add support for specific ECC strength Date: Tue, 6 Feb 2018 18:40:21 +0100 Message-Id: <20180206174021.5947-2-stefan@agner.ch> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180206174021.5947-1-stefan@agner.ch> References: <20180206174021.5947-1-stefan@agner.ch> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1517938383; bh=jVR8ZfyK4qgib9P/qUSr3SD/blggnmH/1LR1xIFYDsA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=pb80a+HCqD7w1FW6hR8/xPWDHBbGzzl3m+WV/bVCrvs4y+AnAX4dnRTUDbo/doErB3lJHZJRoIjdA26/7N+jgVy/xi2p+csj4wHSy8aCvIatUsfWTZNBIAcAI7oOoZYz0EH/xSstzjzRUq/jfwvgsRPF4ZFTuYvI6v64qTrh/Ws= 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 --- .../devicetree/bindings/mtd/gpmi-nand.txt | 5 ++++ drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 29 ++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt index eb2d9919d063..ea6e9b735160 100644 --- a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt +++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt @@ -46,6 +46,11 @@ Optional properties: partitions written from Linux with this feature turned on may not be accessible by the BootROM code. + - nand-ecc-strength: integer representing the number of bits to correct + per ECC step. Needs to be a multiple of 2. + - nand-ecc-step-size: integer representing the number of data bytes + that are covered by a single ECC step. The driver + supports 512 and 1024. The device tree may optionally contain sub-nodes describing partitions of the address space. See partition.txt for more detail. diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index 50f8d4a1b983..8cb378358e11 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -198,17 +198,15 @@ 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 +219,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 +228,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 +421,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.1