diff mbox

mtd: orion_nand: support selecting ECC mode via the device tree

Message ID 1447336537-3705-1-git-send-email-debrabander@gmail.com
State Changes Requested
Headers show

Commit Message

Frank de Brabander Nov. 12, 2015, 1:55 p.m. UTC
Currently the Orion NAND ECC mode is hardcoded to NAND_ECC_SOFT, it does not
allow selecting any other ECC mode. This change makes it possible to use the
device tree to select other ECC modes. It still defaults to the original
mode NAND_ECC_SOFT.

This makes the driver more in line with other mtd nand drivers, that already
support similar ways to select the ECC mode.

Signed-off-by: Frank de Brabander <debrabander@gmail.com>
---
 Documentation/devicetree/bindings/mtd/orion-nand.txt | 4 ++++
 drivers/mtd/nand/orion_nand.c                        | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Richard Weinberger Nov. 12, 2015, 3:01 p.m. UTC | #1
On Thu, Nov 12, 2015 at 2:55 PM, Frank de Brabander
<debrabander@gmail.com> wrote:
> Currently the Orion NAND ECC mode is hardcoded to NAND_ECC_SOFT, it does not
> allow selecting any other ECC mode. This change makes it possible to use the
> device tree to select other ECC modes. It still defaults to the original
> mode NAND_ECC_SOFT.
>
> This makes the driver more in line with other mtd nand drivers, that already
> support similar ways to select the ECC mode.
>
> Signed-off-by: Frank de Brabander <debrabander@gmail.com>
> ---
>  Documentation/devicetree/bindings/mtd/orion-nand.txt | 4 ++++
>  drivers/mtd/nand/orion_nand.c                        | 6 +++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/mtd/orion-nand.txt b/Documentation/devicetree/bindings/mtd/orion-nand.txt
> index 2d6ab66..908c321 100644
> --- a/Documentation/devicetree/bindings/mtd/orion-nand.txt
> +++ b/Documentation/devicetree/bindings/mtd/orion-nand.txt
> @@ -11,6 +11,9 @@ Optional properties:
>  - bank-width : Width in bytes of the device. Default is 1
>  - chip-delay : Chip dependent delay for transferring data from array to read
>                 registers in usecs
> +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> +  "soft_bch".

Does the driver (and the NFC) really support all these modes?
Frank de Brabander Nov. 16, 2015, 10:16 a.m. UTC | #2
2015-11-12 16:01 GMT+01:00 Richard Weinberger <richard.weinberger@gmail.com>:
>
> On Thu, Nov 12, 2015 at 2:55 PM, Frank de Brabander
> <debrabander@gmail.com> wrote:
> > Currently the Orion NAND ECC mode is hardcoded to NAND_ECC_SOFT, it does not
> > allow selecting any other ECC mode. This change makes it possible to use the
> > device tree to select other ECC modes. It still defaults to the original
> > mode NAND_ECC_SOFT.
> >
> > This makes the driver more in line with other mtd nand drivers, that already
> > support similar ways to select the ECC mode.
> >
> > Signed-off-by: Frank de Brabander <debrabander@gmail.com>
> > ---
> >  Documentation/devicetree/bindings/mtd/orion-nand.txt | 4 ++++
> >  drivers/mtd/nand/orion_nand.c                        | 6 +++++-
> >  2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/devicetree/bindings/mtd/orion-nand.txt b/Documentation/devicetree/bindings/mtd/orion-nand.txt
> > index 2d6ab66..908c321 100644
> > --- a/Documentation/devicetree/bindings/mtd/orion-nand.txt
> > +++ b/Documentation/devicetree/bindings/mtd/orion-nand.txt
> > @@ -11,6 +11,9 @@ Optional properties:
> >  - bank-width : Width in bytes of the device. Default is 1
> >  - chip-delay : Chip dependent delay for transferring data from array to read
> >                 registers in usecs
> > +- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
> > +  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
> > +  "soft_bch".
>
> Does the driver (and the NFC) really support all these modes?
>
> --
> Thanks,
> //richard

Good point, thanks. Only "none", "soft", and "soft_bch" are supported.
Will change the documentation and send the updated patch.

Frank
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/mtd/orion-nand.txt b/Documentation/devicetree/bindings/mtd/orion-nand.txt
index 2d6ab66..908c321 100644
--- a/Documentation/devicetree/bindings/mtd/orion-nand.txt
+++ b/Documentation/devicetree/bindings/mtd/orion-nand.txt
@@ -11,6 +11,9 @@  Optional properties:
 - bank-width : Width in bytes of the device. Default is 1
 - chip-delay : Chip dependent delay for transferring data from array to read
                registers in usecs
+- nand-ecc-mode : String, operation mode of the NAND ecc mode, soft by default.
+  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
+  "soft_bch".
 
 The device tree may optionally contain sub-nodes describing partitions of the
 address space. See partition.txt for more detail.
@@ -26,6 +29,7 @@  nand@f4000000 {
 	chip-delay = <25>;
 	compatible = "marvell,orion-nand";
 	reg = <0xf4000000 0x400>;
+	nand-ecc-mode = "soft_bch";
 
 	partition@0 {
 		label = "u-boot";
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index ee83749..004562a 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -14,6 +14,7 @@ 
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/of.h>
+#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -84,6 +85,7 @@  static int __init orion_nand_probe(struct platform_device *pdev)
 	void __iomem *io_base;
 	int ret = 0;
 	u32 val = 0;
+	int ecc_mode = 0;
 
 	nc = devm_kzalloc(&pdev->dev,
 			sizeof(struct nand_chip) + sizeof(struct mtd_info),
@@ -130,7 +132,9 @@  static int __init orion_nand_probe(struct platform_device *pdev)
 	nc->IO_ADDR_R = nc->IO_ADDR_W = io_base;
 	nc->cmd_ctrl = orion_nand_cmd_ctrl;
 	nc->read_buf = orion_nand_read_buf;
-	nc->ecc.mode = NAND_ECC_SOFT;
+
+	ecc_mode = of_get_nand_ecc_mode(pdev->dev.of_node);
+	nc->ecc.mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
 
 	if (board->chip_delay)
 		nc->chip_delay = board->chip_delay;