From patchwork Fri Feb 12 18:11:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 582262 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 09279140B97 for ; Sat, 13 Feb 2016 05:11:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=CGj3gsLS; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751286AbcBLSL6 (ORCPT ); Fri, 12 Feb 2016 13:11:58 -0500 Received: from mail-lb0-f193.google.com ([209.85.217.193]:32992 "EHLO mail-lb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750844AbcBLSL5 (ORCPT ); Fri, 12 Feb 2016 13:11:57 -0500 Received: by mail-lb0-f193.google.com with SMTP id bc4so3921843lbc.0 for ; Fri, 12 Feb 2016 10:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=FPHtzcKkcQ9h225501dZTZIRLAXDhPd3OkN6aYuchnI=; b=CGj3gsLS53F1YIpwMbBRsXcQ3Kh7Hdw9U2Todq/Z5SfrypRqGEzKmvE+srb9TsvpZR 5ieXHm0L+sE2O/5q01RWZuxrQVCgSFv18NqH5LfdesLRUlWYe8eT8chQ+sWNh74O9qMt Qtk2L89iDHeFllZQwrIIZYS3hJfux/uVAKiiFS0Lu87VGPHHZBlfWfzKXQ4oQ+z72TRo UmRZO42v/9L23QTxIy35FkBaYqVsYuEoi2GFb8OE5OFj50WqAdPXCsc3jrUGPt5asDdK J05CyLYfp2Au90mWdwUaLRSzf5EqSZQG2dOR7AA9qf8wnytxVmnKRZ3vWzdENIsBuCDT aozg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=FPHtzcKkcQ9h225501dZTZIRLAXDhPd3OkN6aYuchnI=; b=fE4s2ovbUSp5qGd1ibaI+PVD3uka0pAtzleMXDkik0s8YGXBDjwDjwWHtF7pXYvQKy 81qnrfWG8e8VxDYoEvLqxjRr+d812N1w9y+ixUWNnQh2h4H8JnuYduPSkV6ts297gjQt ruZJcMeNFAyL8SkmmmK+X7zDkHMCt0LVzGVnYD3uHhtyfBedvVkGaXGIQUIdGu/bUttk qy7UrozURuLK1j5bclMWgzgYAh8cainiavK37sv3AX/lU5H1xZLnJlLBNDq5nWy7dWxd ZM/mnlZ0Ai80jDe5HwUe5ArX7RSONqOMuMCkwv9VTZhQnlK06nPT02BeUA9RVAx6yH8N f+TQ== X-Gm-Message-State: AG10YOSxxxHioaTayczb4i88CtvXIQxDln9Xor9/AJv8a+wPUzN2zEnm75bYKanO706YaA== X-Received: by 10.112.143.163 with SMTP id sf3mr1180456lbb.117.1455300715327; Fri, 12 Feb 2016 10:11:55 -0800 (PST) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id n96sm2033721lfi.45.2016.02.12.10.11.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2016 10:11:54 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Brian Norris , linux-mtd@lists.infradead.org Cc: Hauke Mehrtens , Kamal Dasu , Rob Herring , Frank Rowand , Grant Likely , devicetree@vger.kernel.org, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Subject: [PATCH 1/3] of: mtd: add helper reading "nand-ecc-algo" from DT Date: Fri, 12 Feb 2016 19:11:23 +0100 Message-Id: <1455300685-27009-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This allows specifying algorithm used for NAND ECC. There are two available values: "bch" and "hamming". It's important as having just ECC parameters (step, strength) isn't enough to determine algorithm, e.g. you can't distinct BCH-1 and Hamming. Signed-off-by: Rafał Miłecki Reviewed-by: Kamal Dasu Reviewed-by: Kamal Dasu Reviewed-by: Kamal Dasu Acked-by: Rob Herring Acked-by: Brian Norris Acked-by: Brian Norris --- Documentation/devicetree/bindings/mtd/nand.txt | 3 +++ drivers/of/of_mtd.c | 33 ++++++++++++++++++++++++++ include/linux/mtd/nand.h | 5 ++++ include/linux/of_mtd.h | 6 +++++ 4 files changed, 47 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt index b53f92e..a2c2df5 100644 --- a/Documentation/devicetree/bindings/mtd/nand.txt +++ b/Documentation/devicetree/bindings/mtd/nand.txt @@ -3,6 +3,9 @@ - nand-ecc-mode : String, operation mode of the NAND ecc mode. Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first", "soft_bch". +- nand-ecc-algo : string, algorithm of NAND ecc. + Supported values are: "bch", "hamming". The default one is + "bch". - nand-bus-width : 8 or 16 bus width if not present 8 - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c index b7361ed..f2a6630 100644 --- a/drivers/of/of_mtd.c +++ b/drivers/of/of_mtd.c @@ -50,6 +50,39 @@ int of_get_nand_ecc_mode(struct device_node *np) EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode); /** + * It maps 'enum nand_ecc_algo' found in include/linux/mtd/nand.h into the + * device tree binding of 'nand-ecc-algo'. + */ +static const char * const nand_ecc_algos[] = { + [NAND_ECC_BCH] = "bch", + [NAND_ECC_HAMMING] = "hamming", +}; + +/** + * of_get_nand_ecc_algo - Get nand ecc algorithm for given device_node + * @np: Pointer to the given device_node + * + * The function gets ecc algorithm string from property 'nand-ecc-algo' and + * returns its index in nand_ecc_algos table, or errno in error case. + */ +int of_get_nand_ecc_algo(struct device_node *np) +{ + const char *pm; + int err, i; + + err = of_property_read_string(np, "nand-ecc-algo", &pm); + if (err < 0) + return err; + + for (i = 0; i < ARRAY_SIZE(nand_ecc_algos); i++) + if (!strcasecmp(pm, nand_ecc_algos[i])) + return i; + + return -ENODEV; +} +EXPORT_SYMBOL_GPL(of_get_nand_ecc_algo); + +/** * of_get_nand_ecc_step_size - Get ECC step size associated to * the required ECC strength (see below). * @np: Pointer to the given device_node diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 7604f4b..25854d2 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -119,6 +119,11 @@ typedef enum { NAND_ECC_SOFT_BCH, } nand_ecc_modes_t; +enum nand_ecc_algo { + NAND_ECC_BCH, + NAND_ECC_HAMMING, +}; + /* * Constants for Hardware ECC */ diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h index e266caa..0f6aca5 100644 --- a/include/linux/of_mtd.h +++ b/include/linux/of_mtd.h @@ -13,6 +13,7 @@ #include int of_get_nand_ecc_mode(struct device_node *np); +int of_get_nand_ecc_algo(struct device_node *np); int of_get_nand_ecc_step_size(struct device_node *np); int of_get_nand_ecc_strength(struct device_node *np); int of_get_nand_bus_width(struct device_node *np); @@ -25,6 +26,11 @@ static inline int of_get_nand_ecc_mode(struct device_node *np) return -ENOSYS; } +static inline int of_get_nand_ecc_algo(struct device_node *np) +{ + return -ENOSYS; +} + static inline int of_get_nand_ecc_step_size(struct device_node *np) { return -ENOSYS;