Patchwork [v2,1/4] mtd: nand: gpio: Determine bus width automatically

login
register
mail settings
Submitter Alexander Shiyan
Date July 30, 2013, 11:05 a.m.
Message ID <1375182325-30003-1-git-send-email-shc_work@mail.ru>
Download mbox | patch
Permalink /patch/263358/
State New
Headers show

Comments

Alexander Shiyan - July 30, 2013, 11:05 a.m.
This patch provide automatically determine of NAND bus width if
"bank-width" parameter is ommited.
Patch depends on "mtd: nand: fix NAND_BUSWIDTH_AUTO for x16 devices".

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 .../devicetree/bindings/mtd/gpio-control-nand.txt         |  4 ++--
 drivers/mtd/nand/gpio.c                                   | 15 ++++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)
Mark Rutland - July 30, 2013, 3:56 p.m.
On Tue, Jul 30, 2013 at 12:05:24PM +0100, Alexander Shiyan wrote:
> This patch provide automatically determine of NAND bus width if
> "bank-width" parameter is ommited.
> Patch depends on "mtd: nand: fix NAND_BUSWIDTH_AUTO for x16 devices".
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  .../devicetree/bindings/mtd/gpio-control-nand.txt         |  4 ++--
>  drivers/mtd/nand/gpio.c                                   | 15 ++++++++++-----
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> index 36ef07d..2ac14d8 100644
> --- a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> +++ b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> @@ -15,8 +15,8 @@ Required properties:
>    optional gpio and may be set to 0 if not present.
>  
>  Optional properties:
> -- bank-width : Width (in bytes) of the device.  If not present, the width
> -  defaults to 1 byte.
> +- bank-width : Width (in bytes) of the device. If not present, the bus width
> +  of the device is determined automatically.

If we're always able to determine the bus width automatically, why would
we ever need to describe it? We should deprecate it instead.

The new binding defines OS behaviour (automatic determination) which is
a property of the OS, not the device. That does not belong in the dt
binding. The old binding implied that not having the bank-width
parameter was equivalent to having a bank-width parameter of 1 byte. If
it's not always possible to probe the width, and some dts somewhere is
relying on the single byte default, we must keep the property.

Thanks,
Mark.
Olof Johansson - July 30, 2013, 4:34 p.m.
On Tue, Jul 30, 2013 at 03:05:24PM +0400, Alexander Shiyan wrote:
> This patch provide automatically determine of NAND bus width if
> "bank-width" parameter is ommited.
> Patch depends on "mtd: nand: fix NAND_BUSWIDTH_AUTO for x16 devices".
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  .../devicetree/bindings/mtd/gpio-control-nand.txt         |  4 ++--
>  drivers/mtd/nand/gpio.c                                   | 15 ++++++++++-----
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> index 36ef07d..2ac14d8 100644
> --- a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> +++ b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
> @@ -15,8 +15,8 @@ Required properties:
>    optional gpio and may be set to 0 if not present.
>  
>  Optional properties:
> -- bank-width : Width (in bytes) of the device.  If not present, the width
> -  defaults to 1 byte.
> +- bank-width : Width (in bytes) of the device. If not present, the bus width
> +  of the device is determined automatically.
>  - chip-delay : chip dependent delay for transferring data from array to
>    read registers (tR).  If not present then a default of 20us is used.
>  - gpio-control-nand,io-sync-reg : A 64-bit physical address for a read

This would break backwards compatibility, something we're now starting to push
back at.

Instead what you can do is add a bank-width-auto property that, if present and
bank-width being absent, will result in the automatic determination of bank
width.


-Olof

Patch

diff --git a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
index 36ef07d..2ac14d8 100644
--- a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
+++ b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt
@@ -15,8 +15,8 @@  Required properties:
   optional gpio and may be set to 0 if not present.
 
 Optional properties:
-- bank-width : Width (in bytes) of the device.  If not present, the width
-  defaults to 1 byte.
+- bank-width : Width (in bytes) of the device. If not present, the bus width
+  of the device is determined automatically.
 - chip-delay : chip dependent delay for transferring data from array to
   read registers (tR).  If not present then a default of 20us is used.
 - gpio-control-nand,io-sync-reg : A 64-bit physical address for a read
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 800a1cc..674a790 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -116,7 +116,8 @@  static int gpio_nand_get_config_of(const struct device *dev,
 			dev_err(dev, "invalid bank-width %u\n", val);
 			return -EINVAL;
 		}
-	}
+	} else
+		plat->options |= NAND_BUSWIDTH_AUTO;
 
 	plat->gpio_rdy = of_get_gpio(dev->of_node, 0);
 	plat->gpio_nce = of_get_gpio(dev->of_node, 1);
@@ -223,6 +224,14 @@  static int gpio_nand_probe(struct platform_device *pdev)
 	if (IS_ERR(chip->IO_ADDR_R))
 		return PTR_ERR(chip->IO_ADDR_R);
 
+	ret = gpio_nand_get_config(&pdev->dev, &gpiomtd->plat);
+	if (ret)
+		return ret;
+
+	if (resource_size(res) < 2)
+		gpiomtd->plat.options &= ~(NAND_BUSWIDTH_16 |
+					   NAND_BUSWIDTH_AUTO);
+
 	res = gpio_nand_get_io_sync(pdev);
 	if (res) {
 		gpiomtd->io_sync = devm_ioremap_resource(&pdev->dev, res);
@@ -230,10 +239,6 @@  static int gpio_nand_probe(struct platform_device *pdev)
 			return PTR_ERR(gpiomtd->io_sync);
 	}
 
-	ret = gpio_nand_get_config(&pdev->dev, &gpiomtd->plat);
-	if (ret)
-		return ret;
-
 	ret = devm_gpio_request(&pdev->dev, gpiomtd->plat.gpio_nce, "NAND NCE");
 	if (ret)
 		return ret;