From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 In-Reply-To: <1455300685-27009-1-git-send-email-zajec5@gmail.com> References: <1455300685-27009-1-git-send-email-zajec5@gmail.com> Date: Mon, 15 Feb 2016 16:28:28 -0500 Message-ID: Subject: Re: [PATCH 1/3] of: mtd: add helper reading "nand-ecc-algo" from DT From: Kamal Dasu Content-Type: multipart/alternative; boundary=047d7bae4622a946ab052bd5b2cd To: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Cc: Brian Norris , linux-mtd@lists.infradead.org, Hauke Mehrtens , Rob Herring , Frank Rowand , Grant Likely , devicetree@vger.kernel.org List-ID: --047d7bae4622a946ab052bd5b2cd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Feb 12, 2016 at 1:11 PM, Rafa=C5=82 Mi=C5=82ecki = wrote: > 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=C5=82 Mi=C5=82ecki > Reviewed-by: Kamal Dasu Thanks Rafal > > --- > 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 presen= t > 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 t= he > + * device tree binding of 'nand-ecc-algo'. > + */ > +static const char * const nand_ecc_algos[] =3D { > + [NAND_ECC_BCH] =3D "bch", > + [NAND_ECC_HAMMING] =3D "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 =3D of_property_read_string(np, "nand-ecc-algo", &pm); > + if (err < 0) > + return err; > + > + for (i =3D 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; > -- > 1.8.4.5 > > --047d7bae4622a946ab052bd5b2cd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On F= ri, Feb 12, 2016 at 1:11 PM, Rafa=C5=82 Mi=C5=82ecki <= zajec5@gmail.com&= gt; wrote:
This allows specifying algorithm used= for NAND ECC. There are two
available values: "bch" and "hamming". It's importa= nt 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=C5=82 Mi=C5=82ecki <zajec5@gmail.com>

=C2=A0Reviewed-by:=C2=A0Kamal Dasu <kdasu.kdev@gmail.com= >

Thanks Rafal
---
=C2=A0Documentation/devicetree/bindings/mtd/nand.txt |=C2=A0 3 +++
=C2=A0drivers/of/of_mtd.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 33 +++++++++++++++++++++= +++++
=C2=A0include/linux/mtd/nand.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 5 ++++
=C2=A0include/linux/of_mtd.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 6 +++++
=C2=A04 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 @@
=C2=A0- nand-ecc-mode : String, operation mode of the NAND ecc mode.
=C2=A0 =C2=A0Supported values are: "none", "soft", &quo= t;hw", "hw_syndrome", "hw_oob_first",
=C2=A0 =C2=A0"soft_bch".
+- nand-ecc-algo : string, algorithm of NAND ecc.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Supported va= lues are: "bch", "hamming". The default one is
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"bch&qu= ot;.
=C2=A0- nand-bus-width : 8 or 16 bus width if not present 8
=C2=A0- nand-on-flash-bbt: boolean to enable on flash bbt option if not pre= sent 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)
=C2=A0EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);

=C2=A0/**
+ * 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[] =3D {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0[NAND_ECC_BCH]=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =3D "bch",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0[NAND_ECC_HAMMING]=C2=A0 =C2=A0 =C2=A0 =3D &quo= t;hamming",
+};
+
+/**
+ * of_get_nand_ecc_algo - Get nand ecc algorithm for given device_node
+ * @np:=C2=A0 =C2=A0 =C2=A0 =C2=A0 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)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0const char *pm;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0int err, i;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0err =3D of_property_read_string(np, "nand-= ecc-algo", &pm);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (err < 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return err;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i < ARRAY_SIZE(nand_ecc_algos)= ; i++)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!strcasecmp(pm,= nand_ecc_algos[i]))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return i;
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_get_nand_ecc_algo);
+
+/**
=C2=A0 * of_get_nand_ecc_step_size - Get ECC step size associated to
=C2=A0 * the required ECC strength (see below).
=C2=A0 * @np:=C2=A0 =C2=A0 =C2=A0 =C2=A0 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 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 NAND_ECC_SOFT_BCH,
=C2=A0} nand_ecc_modes_t;

+enum nand_ecc_algo {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0NAND_ECC_BCH,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0NAND_ECC_HAMMING,
+};
+
=C2=A0/*
=C2=A0 * Constants for Hardware ECC
=C2=A0 */
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 @@

=C2=A0#include <linux/of.h>
=C2=A0int of_get_nand_ecc_mode(struct device_node *np);
+int of_get_nand_ecc_algo(struct device_node *np);
=C2=A0int of_get_nand_ecc_step_size(struct device_node *np);
=C2=A0int of_get_nand_ecc_strength(struct device_node *np);
=C2=A0int of_get_nand_bus_width(struct device_node *np);
@@ -25,6 +26,11 @@ static inline int of_get_nand_ecc_mode(struct device_nod= e *np)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return -ENOSYS;
=C2=A0}

+static inline int of_get_nand_ecc_algo(struct device_node *np)
+{
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return -ENOSYS;
+}
+
=C2=A0static inline int of_get_nand_ecc_step_size(struct device_node *np) =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return -ENOSYS;
--
1.8.4.5


--047d7bae4622a946ab052bd5b2cd--