All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] of: mtd: add helper reading "nand-ecc-algo" from DT
@ 2016-02-12 18:11 ` Rafał Miłecki
  0 siblings, 0 replies; 43+ messages in thread
From: Rafał Miłecki @ 2016-02-12 18:11 UTC (permalink / raw)
  To: Brian Norris, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Hauke Mehrtens, Kamal Dasu, Rob Herring, Frank Rowand,
	Grant Likely, devicetree-u79uwXL29TY76Z2rM5mHXA,
	Rafał Miłecki

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 <zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 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 <linux/of.h>
 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;
-- 
1.8.4.5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2016-04-01 21:24 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-12 18:11 [PATCH 1/3] of: mtd: add helper reading "nand-ecc-algo" from DT Rafał Miłecki
2016-02-12 18:11 ` Rafał Miłecki
2016-02-15 21:28 ` Kamal Dasu
     [not found] ` <1455300685-27009-1-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-02-12 18:11   ` [PATCH 2/3] mtd: nand: read (from DT) and store ECC algorithm Rafał Miłecki
2016-02-12 18:11     ` Rafał Miłecki
     [not found]     ` <1455300685-27009-2-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-02-15 21:31       ` Kamal Dasu
2016-02-15 21:31         ` Kamal Dasu
2016-04-01 16:02       ` Brian Norris
2016-04-01 16:02         ` Brian Norris
2016-04-01 16:07       ` Brian Norris
2016-04-01 16:07         ` Brian Norris
     [not found]         ` <20160401160722.GC117117-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2016-04-01 19:32           ` Rafał Miłecki
2016-04-01 19:32             ` Rafał Miłecki
     [not found]             ` <CACna6rz6mYSxAr1oSjcLc__sSKM1XdUf-cGOFanGvuij0nNC5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-01 20:07               ` Brian Norris
2016-04-01 20:07                 ` Brian Norris
2016-04-01 21:23                 ` Rafał Miłecki
2016-04-01 21:23                   ` Rafał Miłecki
2016-02-12 18:11   ` [PATCH 3/3] mtd: brcmnand: fix check for Hamming algorithm Rafał Miłecki
2016-02-12 18:11     ` Rafał Miłecki
     [not found]     ` <1455300685-27009-3-git-send-email-zajec5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-02-15 21:30       ` Kamal Dasu
2016-02-15 21:30         ` Kamal Dasu
2016-04-01 16:07       ` Brian Norris
2016-04-01 16:07         ` Brian Norris
2016-02-15 21:43   ` [PATCH 1/3] of: mtd: add helper reading "nand-ecc-algo" from DT Kamal Dasu
2016-02-15 21:43     ` Kamal Dasu
2016-02-22  2:54   ` Rob Herring
2016-02-22  2:54     ` Rob Herring
2016-02-24 13:46   ` Boris Brezillon
2016-02-24 13:46     ` Boris Brezillon
2016-02-25 19:56     ` Rafał Miłecki
2016-02-25 19:56       ` Rafał Miłecki
     [not found]       ` <CACna6rxemvBOu9fy9KP0327TsqonO7dFY5EsQjf1k9Ln6hX8cw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-25 20:09         ` Boris Brezillon
2016-02-25 20:09           ` Boris Brezillon
2016-02-26 16:30           ` Rafał Miłecki
2016-02-26 16:30             ` Rafał Miłecki
     [not found]             ` <CACna6ryVuqSLv8WdzzGUQzpA-F35JxXoHoa2jcLzZeHaXtoexA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-26 16:55               ` Boris Brezillon
2016-02-26 16:55                 ` Boris Brezillon
2016-02-26 21:24                 ` Rafał Miłecki
2016-02-26 21:24                   ` Rafał Miłecki
     [not found]                   ` <CACna6rzRROfYwagsBGo5b8d_bydUBrJ=9RvGZSt1G85xP=gKaw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-26 21:28                     ` Boris Brezillon
2016-02-26 21:28                       ` Boris Brezillon
2016-04-01 16:01   ` Brian Norris
2016-04-01 16:01     ` Brian Norris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.