All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] SPI NOR - force 3byte addressing mode
@ 2017-08-28 21:14 ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-mtd, linux-spi
  Cc: robh+dt, mark.rutland, will.deacon, cyrille.pitchen, marek.vasut,
	broonie, thomas.petazzoni, gregory.clement, nadavh, neta, omrii,
	hannah, mw, jaz, tn

Hi,

This very short patchset introduces optional forcing via DT
3byte addressing mode for accessing the SPI flash, whose
size exceeds 16MiB.

It can be used in case the device does not support
SPI_NOR_4B_OPCODES and helps overcome an issue, when
the Boot ROM cannot handle non-default settings
that could be enabled in the kernel and remain after soft reset.

I'm looking forward to any comments or remarks.

Best regards,
Marcin

Marcin Wojtas (2):
  mtd: spi-nor: add an option to force 3byte adressing mode
  arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB

 Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
 arch/arm64/boot/dts/marvell/armada-7040-db.dts    |  1 +
 drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

-- 
1.8.3.1

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

* [PATCH 0/2] SPI NOR - force 3byte addressing mode
@ 2017-08-28 21:14 ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-spi-u79uwXL29TY76Z2rM5mHXA
  Cc: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	will.deacon-5wv7dgnIgG8, cyrille.pitchen-yU5RGvR974pGWvitb5QawA,
	marek.vasut-Re5JQEeQqe8AvxtiuMwx3w,
	broonie-DgEjT+Ai2ygdnm+yROfE0A,
	thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	gregory.clement-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
	nadavh-eYqpPyKDWXRBDgjK7y7TUQ, neta-eYqpPyKDWXRBDgjK7y7TUQ,
	omrii-eYqpPyKDWXRBDgjK7y7TUQ, hannah-eYqpPyKDWXRBDgjK7y7TUQ,
	mw-nYOzD4b6Jr9Wk0Htik3J/w, jaz-nYOzD4b6Jr9Wk0Htik3J/w,
	tn-nYOzD4b6Jr9Wk0Htik3J/w

Hi,

This very short patchset introduces optional forcing via DT
3byte addressing mode for accessing the SPI flash, whose
size exceeds 16MiB.

It can be used in case the device does not support
SPI_NOR_4B_OPCODES and helps overcome an issue, when
the Boot ROM cannot handle non-default settings
that could be enabled in the kernel and remain after soft reset.

I'm looking forward to any comments or remarks.

Best regards,
Marcin

Marcin Wojtas (2):
  mtd: spi-nor: add an option to force 3byte adressing mode
  arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB

 Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
 arch/arm64/boot/dts/marvell/armada-7040-db.dts    |  1 +
 drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" 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	[flat|nested] 20+ messages in thread

* [PATCH 0/2] SPI NOR - force 3byte addressing mode
@ 2017-08-28 21:14 ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

This very short patchset introduces optional forcing via DT
3byte addressing mode for accessing the SPI flash, whose
size exceeds 16MiB.

It can be used in case the device does not support
SPI_NOR_4B_OPCODES and helps overcome an issue, when
the Boot ROM cannot handle non-default settings
that could be enabled in the kernel and remain after soft reset.

I'm looking forward to any comments or remarks.

Best regards,
Marcin

Marcin Wojtas (2):
  mtd: spi-nor: add an option to force 3byte adressing mode
  arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB

 Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
 arch/arm64/boot/dts/marvell/armada-7040-db.dts    |  1 +
 drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

-- 
1.8.3.1

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
  2017-08-28 21:14 ` Marcin Wojtas
@ 2017-08-28 21:14   ` Marcin Wojtas
  -1 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-mtd, linux-spi
  Cc: robh+dt, mark.rutland, will.deacon, cyrille.pitchen, marek.vasut,
	broonie, thomas.petazzoni, gregory.clement, nadavh, neta, omrii,
	hannah, mw, jaz, tn

Hitherto code set 4B addressing mode for all SPI flashes whose
size exceeds 16MB. However, changing the default 3B access
in some cases may be harmful - it may happen that the Boot ROM
is not capable of handling non-default state of the SPI NOR
(e.g. after soft reset). Some flash devices allow to access the
memory above 128Mib without changing mode to 4byte thanks
to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
for those which don't support them, the problem persists.

This patch adds optional property that can be added to the
SPI flash node and which will force to use 3B addressing mode,
limiting the accessible memory size to 16MiB.
Binding documentation is updated accordingly.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
 drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
index 1f6e86f..f13b773 100644
--- a/Documentation/devicetree/bindings/spi/spi-bus.txt
+++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
@@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
 		    Defaults to 1 if not present.
 - spi-rx-delay-us - Microsecond delay after a read transfer.
 - spi-tx-delay-us - Microsecond delay after a write transfer.
+- spi-3byte-addressing - Empty property indicating device access to be done
+		    only in 3byte addressing mode.
 
 Some SPI controllers and devices support Dual and Quad SPI transfer mode.
 It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1413828..029c87d 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
 		    info->flags & SPI_NOR_4B_OPCODES)
 			spi_nor_set_4byte_opcodes(nor, info);
-		else
+		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
+			/*
+			 * Do not enter 4byte mode in order to prevent
+			 * the early bootloader to come up on non-default
+			 * SPI NOR memory during boot. Limit accessible
+			 * size to 16MiB.
+			 */
+			nor->addr_width = 3;
+			mtd->size = 0x1000000;
+			dev_info(dev, "Force 3B addressing mode\n");
+		} else
 			set_4byte(nor, info, 1);
 	} else {
 		nor->addr_width = 3;
-- 
1.8.3.1

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:14   ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-arm-kernel

Hitherto code set 4B addressing mode for all SPI flashes whose
size exceeds 16MB. However, changing the default 3B access
in some cases may be harmful - it may happen that the Boot ROM
is not capable of handling non-default state of the SPI NOR
(e.g. after soft reset). Some flash devices allow to access the
memory above 128Mib without changing mode to 4byte thanks
to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
for those which don't support them, the problem persists.

This patch adds optional property that can be added to the
SPI flash node and which will force to use 3B addressing mode,
limiting the accessible memory size to 16MiB.
Binding documentation is updated accordingly.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
 drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
index 1f6e86f..f13b773 100644
--- a/Documentation/devicetree/bindings/spi/spi-bus.txt
+++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
@@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
 		    Defaults to 1 if not present.
 - spi-rx-delay-us - Microsecond delay after a read transfer.
 - spi-tx-delay-us - Microsecond delay after a write transfer.
+- spi-3byte-addressing - Empty property indicating device access to be done
+		    only in 3byte addressing mode.
 
 Some SPI controllers and devices support Dual and Quad SPI transfer mode.
 It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 1413828..029c87d 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
 		    info->flags & SPI_NOR_4B_OPCODES)
 			spi_nor_set_4byte_opcodes(nor, info);
-		else
+		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
+			/*
+			 * Do not enter 4byte mode in order to prevent
+			 * the early bootloader to come up on non-default
+			 * SPI NOR memory during boot. Limit accessible
+			 * size to 16MiB.
+			 */
+			nor->addr_width = 3;
+			mtd->size = 0x1000000;
+			dev_info(dev, "Force 3B addressing mode\n");
+		} else
 			set_4byte(nor, info, 1);
 	} else {
 		nor->addr_width = 3;
-- 
1.8.3.1

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

* [PATCH 2/2] arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB
  2017-08-28 21:14 ` Marcin Wojtas
@ 2017-08-28 21:14   ` Marcin Wojtas
  -1 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-mtd, linux-spi
  Cc: robh+dt, mark.rutland, will.deacon, cyrille.pitchen, marek.vasut,
	broonie, thomas.petazzoni, gregory.clement, nadavh, neta, omrii,
	hannah, mw, jaz, tn

Armada 7040 DB boards can be shipped with various models of
boot SPI flash devices. An issue can emerge, when their size
exceeds 16MB - in such case the kernel driver will switch automatically
to 4B addressing mode. Later, in case of soft reset, the Boot ROM
will fail to fetch the firmware during the board initialization.

In order to prevent such behavior, this patch forces 3B addressing
mode used on affected boards by adding newly introduced
'spi-3byte-addressing' property to the SPI flash nodes.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 arch/arm64/boot/dts/marvell/armada-7040-db.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/marvell/armada-7040-db.dts b/arch/arm64/boot/dts/marvell/armada-7040-db.dts
index 92c761c..d0bd296 100644
--- a/arch/arm64/boot/dts/marvell/armada-7040-db.dts
+++ b/arch/arm64/boot/dts/marvell/armada-7040-db.dts
@@ -116,6 +116,7 @@
 		compatible = "jedec,spi-nor";
 		reg = <0x0>;
 		spi-max-frequency = <20000000>;
+		spi-3byte-addressing;
 
 		partitions {
 			compatible = "fixed-partitions";
-- 
1.8.3.1

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

* [PATCH 2/2] arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB
@ 2017-08-28 21:14   ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:14 UTC (permalink / raw)
  To: linux-arm-kernel

Armada 7040 DB boards can be shipped with various models of
boot SPI flash devices. An issue can emerge, when their size
exceeds 16MB - in such case the kernel driver will switch automatically
to 4B addressing mode. Later, in case of soft reset, the Boot ROM
will fail to fetch the firmware during the board initialization.

In order to prevent such behavior, this patch forces 3B addressing
mode used on affected boards by adding newly introduced
'spi-3byte-addressing' property to the SPI flash nodes.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 arch/arm64/boot/dts/marvell/armada-7040-db.dts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/marvell/armada-7040-db.dts b/arch/arm64/boot/dts/marvell/armada-7040-db.dts
index 92c761c..d0bd296 100644
--- a/arch/arm64/boot/dts/marvell/armada-7040-db.dts
+++ b/arch/arm64/boot/dts/marvell/armada-7040-db.dts
@@ -116,6 +116,7 @@
 		compatible = "jedec,spi-nor";
 		reg = <0x0>;
 		spi-max-frequency = <20000000>;
+		spi-3byte-addressing;
 
 		partitions {
 			compatible = "fixed-partitions";
-- 
1.8.3.1

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
  2017-08-28 21:14   ` Marcin Wojtas
  (?)
@ 2017-08-28 21:18     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 20+ messages in thread
From: Geert Uytterhoeven @ 2017-08-28 21:18 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: linux-kernel, linux-arm-kernel, MTD Maling List, linux-spi,
	Rob Herring, Mark Rutland, Will Deacon, Cyrille Pitchen,
	Marek Vasut, Mark Brown, Thomas Petazzoni, Gregory Clement,
	Nadav Haklai, neta, omrii, Hanna Hawa, Grzegorz Jaszczyk, tn

On Mon, Aug 28, 2017 at 11:14 PM, Marcin Wojtas <mw@semihalf.com> wrote:
> Hitherto code set 4B addressing mode for all SPI flashes whose
> size exceeds 16MB. However, changing the default 3B access
> in some cases may be harmful - it may happen that the Boot ROM
> is not capable of handling non-default state of the SPI NOR
> (e.g. after soft reset). Some flash devices allow to access the
> memory above 128Mib without changing mode to 4byte thanks
> to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
> for those which don't support them, the problem persists.
>
> This patch adds optional property that can be added to the
> SPI flash node and which will force to use 3B addressing mode,
> limiting the accessible memory size to 16MiB.
> Binding documentation is updated accordingly.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
>  drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
> index 1f6e86f..f13b773 100644
> --- a/Documentation/devicetree/bindings/spi/spi-bus.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
> @@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
>                     Defaults to 1 if not present.
>  - spi-rx-delay-us - Microsecond delay after a read transfer.
>  - spi-tx-delay-us - Microsecond delay after a write transfer.
> +- spi-3byte-addressing - Empty property indicating device access to be done
> +                   only in 3byte addressing mode.

spi-force-3byte-addressing?

>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>                     info->flags & SPI_NOR_4B_OPCODES)
>                         spi_nor_set_4byte_opcodes(nor, info);
> -               else
> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +                       /*
> +                        * Do not enter 4byte mode in order to prevent
> +                        * the early bootloader to come up on non-default
> +                        * SPI NOR memory during boot. Limit accessible
> +                        * size to 16MiB.
> +                        */
> +                       nor->addr_width = 3;
> +                       mtd->size = 0x1000000;

What if the device is smaller than 16 MiB?

mtd->size = min(mtd->size, 0x1000000);

> +                       dev_info(dev, "Force 3B addressing mode\n");
> +               } else
>                         set_4byte(nor, info, 1);
>         } else {
>                 nor->addr_width = 3;

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:18     ` Geert Uytterhoeven
  0 siblings, 0 replies; 20+ messages in thread
From: Geert Uytterhoeven @ 2017-08-28 21:18 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: linux-kernel, linux-arm-kernel, MTD Maling List, linux-spi,
	Rob Herring, Mark Rutland, Will Deacon, Cyrille Pitchen,
	Marek Vasut, Mark Brown, Thomas Petazzoni, Gregory Clement,
	Nadav Haklai, neta, omrii, Hanna Hawa, Grzegorz Jaszczyk, tn

On Mon, Aug 28, 2017 at 11:14 PM, Marcin Wojtas <mw@semihalf.com> wrote:
> Hitherto code set 4B addressing mode for all SPI flashes whose
> size exceeds 16MB. However, changing the default 3B access
> in some cases may be harmful - it may happen that the Boot ROM
> is not capable of handling non-default state of the SPI NOR
> (e.g. after soft reset). Some flash devices allow to access the
> memory above 128Mib without changing mode to 4byte thanks
> to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
> for those which don't support them, the problem persists.
>
> This patch adds optional property that can be added to the
> SPI flash node and which will force to use 3B addressing mode,
> limiting the accessible memory size to 16MiB.
> Binding documentation is updated accordingly.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
>  drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
> index 1f6e86f..f13b773 100644
> --- a/Documentation/devicetree/bindings/spi/spi-bus.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
> @@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
>                     Defaults to 1 if not present.
>  - spi-rx-delay-us - Microsecond delay after a read transfer.
>  - spi-tx-delay-us - Microsecond delay after a write transfer.
> +- spi-3byte-addressing - Empty property indicating device access to be done
> +                   only in 3byte addressing mode.

spi-force-3byte-addressing?

>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>                     info->flags & SPI_NOR_4B_OPCODES)
>                         spi_nor_set_4byte_opcodes(nor, info);
> -               else
> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +                       /*
> +                        * Do not enter 4byte mode in order to prevent
> +                        * the early bootloader to come up on non-default
> +                        * SPI NOR memory during boot. Limit accessible
> +                        * size to 16MiB.
> +                        */
> +                       nor->addr_width = 3;
> +                       mtd->size = 0x1000000;

What if the device is smaller than 16 MiB?

mtd->size = min(mtd->size, 0x1000000);

> +                       dev_info(dev, "Force 3B addressing mode\n");
> +               } else
>                         set_4byte(nor, info, 1);
>         } else {
>                 nor->addr_width = 3;

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:18     ` Geert Uytterhoeven
  0 siblings, 0 replies; 20+ messages in thread
From: Geert Uytterhoeven @ 2017-08-28 21:18 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Aug 28, 2017 at 11:14 PM, Marcin Wojtas <mw@semihalf.com> wrote:
> Hitherto code set 4B addressing mode for all SPI flashes whose
> size exceeds 16MB. However, changing the default 3B access
> in some cases may be harmful - it may happen that the Boot ROM
> is not capable of handling non-default state of the SPI NOR
> (e.g. after soft reset). Some flash devices allow to access the
> memory above 128Mib without changing mode to 4byte thanks
> to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
> for those which don't support them, the problem persists.
>
> This patch adds optional property that can be added to the
> SPI flash node and which will force to use 3B addressing mode,
> limiting the accessible memory size to 16MiB.
> Binding documentation is updated accordingly.
>
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
>  drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
> index 1f6e86f..f13b773 100644
> --- a/Documentation/devicetree/bindings/spi/spi-bus.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
> @@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
>                     Defaults to 1 if not present.
>  - spi-rx-delay-us - Microsecond delay after a read transfer.
>  - spi-tx-delay-us - Microsecond delay after a write transfer.
> +- spi-3byte-addressing - Empty property indicating device access to be done
> +                   only in 3byte addressing mode.

spi-force-3byte-addressing?

>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>                     info->flags & SPI_NOR_4B_OPCODES)
>                         spi_nor_set_4byte_opcodes(nor, info);
> -               else
> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +                       /*
> +                        * Do not enter 4byte mode in order to prevent
> +                        * the early bootloader to come up on non-default
> +                        * SPI NOR memory during boot. Limit accessible
> +                        * size to 16MiB.
> +                        */
> +                       nor->addr_width = 3;
> +                       mtd->size = 0x1000000;

What if the device is smaller than 16 MiB?

mtd->size = min(mtd->size, 0x1000000);

> +                       dev_info(dev, "Force 3B addressing mode\n");
> +               } else
>                         set_4byte(nor, info, 1);
>         } else {
>                 nor->addr_width = 3;

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:54       ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:54 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel, linux-arm-kernel, MTD Maling List, linux-spi,
	Rob Herring, Mark Rutland, Will Deacon, Cyrille Pitchen,
	Marek Vasut, Mark Brown, Thomas Petazzoni, Gregory Clement,
	Nadav Haklai, Neta Zur Hershkovits, Omri Itach, Hanna Hawa,
	Grzegorz Jaszczyk, Tomasz Nowicki

Hi Geert,

>> +- spi-3byte-addressing - Empty property indicating device access to be done
>> +                   only in 3byte addressing mode.
>
> spi-force-3byte-addressing?

I can change it, no problem. I thought of this, but was affraid if the
property wouldn't be too long.

>
>>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 1413828..029c87d 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>>                     info->flags & SPI_NOR_4B_OPCODES)
>>                         spi_nor_set_4byte_opcodes(nor, info);
>> -               else
>> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
>> +                       /*
>> +                        * Do not enter 4byte mode in order to prevent
>> +                        * the early bootloader to come up on non-default
>> +                        * SPI NOR memory during boot. Limit accessible
>> +                        * size to 16MiB.
>> +                        */
>> +                       nor->addr_width = 3;
>> +                       mtd->size = 0x1000000;
>
> What if the device is smaller than 16 MiB?
>
> mtd->size = min(mtd->size, 0x1000000);

Not needed - this code is executed only for mtd->size > 0x1000000. See
bigger context:

        if (info->addr_width)
                nor->addr_width = info->addr_width;
        else if (mtd->size > 0x1000000) {
                /* enable 4-byte addressing if the device exceeds 16MiB */
                nor->addr_width = 4;
                if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
                    info->flags & SPI_NOR_4B_OPCODES)
                        spi_nor_set_4byte_opcodes(nor, info);
                else if (of_property_read_bool(np, "spi-3byte-addressing")) {
                        /*
                         * Do not enter 4byte mode in order to prevent
                         * the early bootloader to come up on non-default
                         * SPI NOR memory during boot. Limit accessible
                         * size to 16MiB.
                         */
                        nor->addr_width = 3;
                        mtd->size = 0x1000000;
                        dev_info(dev, "Force 3B addressing mode\n");
                } else
                        set_4byte(nor, info, 1);
        } else {
                nor->addr_width = 3;
        }


Best regards,
Marcin

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:54       ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:54 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	MTD Maling List, linux-spi, Rob Herring, Mark Rutland,
	Will Deacon, Cyrille Pitchen, Marek Vasut, Mark Brown,
	Thomas Petazzoni, Gregory Clement, Nadav Haklai,
	Neta Zur Hershkovits, Omri Itach, Hanna Hawa, Grzegorz Jaszczyk,
	Tomasz

Hi Geert,

>> +- spi-3byte-addressing - Empty property indicating device access to be done
>> +                   only in 3byte addressing mode.
>
> spi-force-3byte-addressing?

I can change it, no problem. I thought of this, but was affraid if the
property wouldn't be too long.

>
>>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 1413828..029c87d 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>>                     info->flags & SPI_NOR_4B_OPCODES)
>>                         spi_nor_set_4byte_opcodes(nor, info);
>> -               else
>> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
>> +                       /*
>> +                        * Do not enter 4byte mode in order to prevent
>> +                        * the early bootloader to come up on non-default
>> +                        * SPI NOR memory during boot. Limit accessible
>> +                        * size to 16MiB.
>> +                        */
>> +                       nor->addr_width = 3;
>> +                       mtd->size = 0x1000000;
>
> What if the device is smaller than 16 MiB?
>
> mtd->size = min(mtd->size, 0x1000000);

Not needed - this code is executed only for mtd->size > 0x1000000. See
bigger context:

        if (info->addr_width)
                nor->addr_width = info->addr_width;
        else if (mtd->size > 0x1000000) {
                /* enable 4-byte addressing if the device exceeds 16MiB */
                nor->addr_width = 4;
                if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
                    info->flags & SPI_NOR_4B_OPCODES)
                        spi_nor_set_4byte_opcodes(nor, info);
                else if (of_property_read_bool(np, "spi-3byte-addressing")) {
                        /*
                         * Do not enter 4byte mode in order to prevent
                         * the early bootloader to come up on non-default
                         * SPI NOR memory during boot. Limit accessible
                         * size to 16MiB.
                         */
                        nor->addr_width = 3;
                        mtd->size = 0x1000000;
                        dev_info(dev, "Force 3B addressing mode\n");
                } else
                        set_4byte(nor, info, 1);
        } else {
                nor->addr_width = 3;
        }


Best regards,
Marcin
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" 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	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:54       ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:54 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel, linux-arm-kernel, MTD Maling List, linux-spi,
	Rob Herring, Mark Rutland, Will Deacon, Cyrille Pitchen,
	Marek Vasut, Mark Brown, Thomas Petazzoni, Gregory Clement,
	Nadav Haklai, Neta Zur Hershkovits, Omri Itach, Hanna Hawa,
	Grzegorz Jaszczyk, Tomasz Nowicki

Hi Geert,

>> +- spi-3byte-addressing - Empty property indicating device access to be done
>> +                   only in 3byte addressing mode.
>
> spi-force-3byte-addressing?

I can change it, no problem. I thought of this, but was affraid if the
property wouldn't be too long.

>
>>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 1413828..029c87d 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>>                     info->flags & SPI_NOR_4B_OPCODES)
>>                         spi_nor_set_4byte_opcodes(nor, info);
>> -               else
>> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
>> +                       /*
>> +                        * Do not enter 4byte mode in order to prevent
>> +                        * the early bootloader to come up on non-default
>> +                        * SPI NOR memory during boot. Limit accessible
>> +                        * size to 16MiB.
>> +                        */
>> +                       nor->addr_width = 3;
>> +                       mtd->size = 0x1000000;
>
> What if the device is smaller than 16 MiB?
>
> mtd->size = min(mtd->size, 0x1000000);

Not needed - this code is executed only for mtd->size > 0x1000000. See
bigger context:

        if (info->addr_width)
                nor->addr_width = info->addr_width;
        else if (mtd->size > 0x1000000) {
                /* enable 4-byte addressing if the device exceeds 16MiB */
                nor->addr_width = 4;
                if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
                    info->flags & SPI_NOR_4B_OPCODES)
                        spi_nor_set_4byte_opcodes(nor, info);
                else if (of_property_read_bool(np, "spi-3byte-addressing")) {
                        /*
                         * Do not enter 4byte mode in order to prevent
                         * the early bootloader to come up on non-default
                         * SPI NOR memory during boot. Limit accessible
                         * size to 16MiB.
                         */
                        nor->addr_width = 3;
                        mtd->size = 0x1000000;
                        dev_info(dev, "Force 3B addressing mode\n");
                } else
                        set_4byte(nor, info, 1);
        } else {
                nor->addr_width = 3;
        }


Best regards,
Marcin

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 21:54       ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-28 21:54 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Geert,

>> +- spi-3byte-addressing - Empty property indicating device access to be done
>> +                   only in 3byte addressing mode.
>
> spi-force-3byte-addressing?

I can change it, no problem. I thought of this, but was affraid if the
property wouldn't be too long.

>
>>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
>> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
>> index 1413828..029c87d 100644
>> --- a/drivers/mtd/spi-nor/spi-nor.c
>> +++ b/drivers/mtd/spi-nor/spi-nor.c
>> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>>                 if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>>                     info->flags & SPI_NOR_4B_OPCODES)
>>                         spi_nor_set_4byte_opcodes(nor, info);
>> -               else
>> +               else if (of_property_read_bool(np, "spi-3byte-addressing")) {
>> +                       /*
>> +                        * Do not enter 4byte mode in order to prevent
>> +                        * the early bootloader to come up on non-default
>> +                        * SPI NOR memory during boot. Limit accessible
>> +                        * size to 16MiB.
>> +                        */
>> +                       nor->addr_width = 3;
>> +                       mtd->size = 0x1000000;
>
> What if the device is smaller than 16 MiB?
>
> mtd->size = min(mtd->size, 0x1000000);

Not needed - this code is executed only for mtd->size > 0x1000000. See
bigger context:

        if (info->addr_width)
                nor->addr_width = info->addr_width;
        else if (mtd->size > 0x1000000) {
                /* enable 4-byte addressing if the device exceeds 16MiB */
                nor->addr_width = 4;
                if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
                    info->flags & SPI_NOR_4B_OPCODES)
                        spi_nor_set_4byte_opcodes(nor, info);
                else if (of_property_read_bool(np, "spi-3byte-addressing")) {
                        /*
                         * Do not enter 4byte mode in order to prevent
                         * the early bootloader to come up on non-default
                         * SPI NOR memory during boot. Limit accessible
                         * size to 16MiB.
                         */
                        nor->addr_width = 3;
                        mtd->size = 0x1000000;
                        dev_info(dev, "Force 3B addressing mode\n");
                } else
                        set_4byte(nor, info, 1);
        } else {
                nor->addr_width = 3;
        }


Best regards,
Marcin

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
  2017-08-28 21:14   ` Marcin Wojtas
@ 2017-08-28 23:24     ` Marek Vasut
  -1 siblings, 0 replies; 20+ messages in thread
From: Marek Vasut @ 2017-08-28 23:24 UTC (permalink / raw)
  To: Marcin Wojtas, linux-kernel, linux-arm-kernel, linux-mtd, linux-spi
  Cc: robh+dt, mark.rutland, will.deacon, cyrille.pitchen, broonie,
	thomas.petazzoni, gregory.clement, nadavh, neta, omrii, hannah,
	jaz, tn

On 08/28/2017 11:14 PM, Marcin Wojtas wrote:
> Hitherto code set 4B addressing mode for all SPI flashes whose
> size exceeds 16MB. However, changing the default 3B access
> in some cases may be harmful - it may happen that the Boot ROM
> is not capable of handling non-default state of the SPI NOR
> (e.g. after soft reset).

No, this happens when your hardware is broken and does NOT reset the
flash while reseting the CPU as well. If the flash is in some funny
state (ie. middle of page program or erase cycle, which takes long OR
4byte addressing mode) and the CPU resets , then if the SPI NOR is not
reset, your system will still get stuck . You need to fix your hardware
such that you use the reset output of your CPU to detect when the CPU
restarted and add logic to reset your storage as well.

This stuff below is a poor workaround and has it's known problems which
can only be solved by fixing the hardware. This problem keeps coming up
repeatedly, just skim through the Linux MTD and U-Boot lists for other
victims of bad HW design. I don't think I want to see it in the kernel
as that would motivate people to use it rather than fixing their HW .

> Some flash devices allow to access the
> memory above 128Mib without changing mode to 4byte thanks
> to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
> for those which don't support them, the problem persists.
> 
> This patch adds optional property that can be added to the
> SPI flash node and which will force to use 3B addressing mode,
> limiting the accessible memory size to 16MiB.
> Binding documentation is updated accordingly.
> 
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
>  drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
> index 1f6e86f..f13b773 100644
> --- a/Documentation/devicetree/bindings/spi/spi-bus.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
> @@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
>  		    Defaults to 1 if not present.
>  - spi-rx-delay-us - Microsecond delay after a read transfer.
>  - spi-tx-delay-us - Microsecond delay after a write transfer.
> +- spi-3byte-addressing - Empty property indicating device access to be done
> +		    only in 3byte addressing mode.
>  
>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>  		    info->flags & SPI_NOR_4B_OPCODES)
>  			spi_nor_set_4byte_opcodes(nor, info);
> -		else
> +		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +			/*
> +			 * Do not enter 4byte mode in order to prevent
> +			 * the early bootloader to come up on non-default
> +			 * SPI NOR memory during boot. Limit accessible
> +			 * size to 16MiB.
> +			 */
> +			nor->addr_width = 3;
> +			mtd->size = 0x1000000;
> +			dev_info(dev, "Force 3B addressing mode\n");
> +		} else
>  			set_4byte(nor, info, 1);
>  	} else {
>  		nor->addr_width = 3;
> 


-- 
Best regards,
Marek Vasut

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-28 23:24     ` Marek Vasut
  0 siblings, 0 replies; 20+ messages in thread
From: Marek Vasut @ 2017-08-28 23:24 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/28/2017 11:14 PM, Marcin Wojtas wrote:
> Hitherto code set 4B addressing mode for all SPI flashes whose
> size exceeds 16MB. However, changing the default 3B access
> in some cases may be harmful - it may happen that the Boot ROM
> is not capable of handling non-default state of the SPI NOR
> (e.g. after soft reset).

No, this happens when your hardware is broken and does NOT reset the
flash while reseting the CPU as well. If the flash is in some funny
state (ie. middle of page program or erase cycle, which takes long OR
4byte addressing mode) and the CPU resets , then if the SPI NOR is not
reset, your system will still get stuck . You need to fix your hardware
such that you use the reset output of your CPU to detect when the CPU
restarted and add logic to reset your storage as well.

This stuff below is a poor workaround and has it's known problems which
can only be solved by fixing the hardware. This problem keeps coming up
repeatedly, just skim through the Linux MTD and U-Boot lists for other
victims of bad HW design. I don't think I want to see it in the kernel
as that would motivate people to use it rather than fixing their HW .

> Some flash devices allow to access the
> memory above 128Mib without changing mode to 4byte thanks
> to special op codes (see SPI_NOR_4B_OPCODES flag). Unfortunately
> for those which don't support them, the problem persists.
> 
> This patch adds optional property that can be added to the
> SPI flash node and which will force to use 3B addressing mode,
> limiting the accessible memory size to 16MiB.
> Binding documentation is updated accordingly.
> 
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Documentation/devicetree/bindings/spi/spi-bus.txt |  2 ++
>  drivers/mtd/spi-nor/spi-nor.c                     | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/devicetree/bindings/spi/spi-bus.txt b/Documentation/devicetree/bindings/spi/spi-bus.txt
> index 1f6e86f..f13b773 100644
> --- a/Documentation/devicetree/bindings/spi/spi-bus.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-bus.txt
> @@ -77,6 +77,8 @@ All slave nodes can contain the following optional properties:
>  		    Defaults to 1 if not present.
>  - spi-rx-delay-us - Microsecond delay after a read transfer.
>  - spi-tx-delay-us - Microsecond delay after a write transfer.
> +- spi-3byte-addressing - Empty property indicating device access to be done
> +		    only in 3byte addressing mode.
>  
>  Some SPI controllers and devices support Dual and Quad SPI transfer mode.
>  It allows data in the SPI system to be transferred using 2 wires (DUAL) or 4
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>  		    info->flags & SPI_NOR_4B_OPCODES)
>  			spi_nor_set_4byte_opcodes(nor, info);
> -		else
> +		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +			/*
> +			 * Do not enter 4byte mode in order to prevent
> +			 * the early bootloader to come up on non-default
> +			 * SPI NOR memory during boot. Limit accessible
> +			 * size to 16MiB.
> +			 */
> +			nor->addr_width = 3;
> +			mtd->size = 0x1000000;
> +			dev_info(dev, "Force 3B addressing mode\n");
> +		} else
>  			set_4byte(nor, info, 1);
>  	} else {
>  		nor->addr_width = 3;
> 


-- 
Best regards,
Marek Vasut

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
  2017-08-28 23:24     ` Marek Vasut
@ 2017-08-29  7:40       ` Marcin Wojtas
  -1 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-29  7:40 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-kernel, linux-arm-kernel, MTD Maling List, linux-spi,
	Rob Herring, Mark Rutland, Will Deacon, Cyrille Pitchen,
	Mark Brown, Thomas Petazzoni, Gregory Clément, nadavh,
	Neta Zur Hershkovits, Omri Itach, Hanna Hawa, jaz,
	Tomasz Nowicki

Hi Marek,

2017-08-29 1:24 GMT+02:00 Marek Vasut <marek.vasut@gmail.com>:
> On 08/28/2017 11:14 PM, Marcin Wojtas wrote:
>> Hitherto code set 4B addressing mode for all SPI flashes whose
>> size exceeds 16MB. However, changing the default 3B access
>> in some cases may be harmful - it may happen that the Boot ROM
>> is not capable of handling non-default state of the SPI NOR
>> (e.g. after soft reset).
>
> No, this happens when your hardware is broken and does NOT reset the
> flash while reseting the CPU as well. If the flash is in some funny
> state (ie. middle of page program or erase cycle, which takes long OR
> 4byte addressing mode) and the CPU resets , then if the SPI NOR is not
> reset, your system will still get stuck . You need to fix your hardware
> such that you use the reset output of your CPU to detect when the CPU
> restarted and add logic to reset your storage as well.
>
> This stuff below is a poor workaround and has it's known problems which
> can only be solved by fixing the hardware. This problem keeps coming up
> repeatedly, just skim through the Linux MTD and U-Boot lists for other
> victims of bad HW design. I don't think I want to see it in the kernel
> as that would motivate people to use it rather than fixing their HW .
>

Understood. I just only got impression that attempts to overcome the
HW design faults in terms of keeping SPI NOR default state during boot
can be added - introducing SPI_NOR_4B_OPCODES seems to have no other
reason, however it favors only a group of devices that support it.

Best regards,
Marcin

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-08-29  7:40       ` Marcin Wojtas
  0 siblings, 0 replies; 20+ messages in thread
From: Marcin Wojtas @ 2017-08-29  7:40 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marek,

2017-08-29 1:24 GMT+02:00 Marek Vasut <marek.vasut@gmail.com>:
> On 08/28/2017 11:14 PM, Marcin Wojtas wrote:
>> Hitherto code set 4B addressing mode for all SPI flashes whose
>> size exceeds 16MB. However, changing the default 3B access
>> in some cases may be harmful - it may happen that the Boot ROM
>> is not capable of handling non-default state of the SPI NOR
>> (e.g. after soft reset).
>
> No, this happens when your hardware is broken and does NOT reset the
> flash while reseting the CPU as well. If the flash is in some funny
> state (ie. middle of page program or erase cycle, which takes long OR
> 4byte addressing mode) and the CPU resets , then if the SPI NOR is not
> reset, your system will still get stuck . You need to fix your hardware
> such that you use the reset output of your CPU to detect when the CPU
> restarted and add logic to reset your storage as well.
>
> This stuff below is a poor workaround and has it's known problems which
> can only be solved by fixing the hardware. This problem keeps coming up
> repeatedly, just skim through the Linux MTD and U-Boot lists for other
> victims of bad HW design. I don't think I want to see it in the kernel
> as that would motivate people to use it rather than fixing their HW .
>

Understood. I just only got impression that attempts to overcome the
HW design faults in terms of keeping SPI NOR default state during boot
can be added - introducing SPI_NOR_4B_OPCODES seems to have no other
reason, however it favors only a group of devices that support it.

Best regards,
Marcin

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

* Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
  2017-08-28 21:14   ` Marcin Wojtas
@ 2017-09-04 16:26     ` Pavel Machek
  -1 siblings, 0 replies; 20+ messages in thread
From: Pavel Machek @ 2017-09-04 16:26 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: linux-kernel, linux-arm-kernel, linux-mtd, linux-spi, robh+dt,
	mark.rutland, will.deacon, cyrille.pitchen, marek.vasut, broonie,
	thomas.petazzoni, gregory.clement, nadavh, neta, omrii, hannah,
	jaz, tn

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

Hi!

> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>  		    info->flags & SPI_NOR_4B_OPCODES)
>  			spi_nor_set_4byte_opcodes(nor, info);
> -		else
> +		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +			/*
> +			 * Do not enter 4byte mode in order to prevent
> +			 * the early bootloader to come up on non-default
> +			 * SPI NOR memory during boot. Limit accessible
> +			 * size to 16MiB.
> +			 */
> +			nor->addr_width = 3;
> +			mtd->size = 0x1000000;
> +			dev_info(dev, "Force 3B addressing mode\n");

I'd append "limiting access to first 16MiB" .. because otherwise
people will wonder where their flash went.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
@ 2017-09-04 16:26     ` Pavel Machek
  0 siblings, 0 replies; 20+ messages in thread
From: Pavel Machek @ 2017-09-04 16:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi!

> index 1413828..029c87d 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2002,7 +2002,17 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
>  		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
>  		    info->flags & SPI_NOR_4B_OPCODES)
>  			spi_nor_set_4byte_opcodes(nor, info);
> -		else
> +		else if (of_property_read_bool(np, "spi-3byte-addressing")) {
> +			/*
> +			 * Do not enter 4byte mode in order to prevent
> +			 * the early bootloader to come up on non-default
> +			 * SPI NOR memory during boot. Limit accessible
> +			 * size to 16MiB.
> +			 */
> +			nor->addr_width = 3;
> +			mtd->size = 0x1000000;
> +			dev_info(dev, "Force 3B addressing mode\n");

I'd append "limiting access to first 16MiB" .. because otherwise
people will wonder where their flash went.
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170904/88a55ffc/attachment.sig>

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

end of thread, other threads:[~2017-09-04 16:26 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-28 21:14 [PATCH 0/2] SPI NOR - force 3byte addressing mode Marcin Wojtas
2017-08-28 21:14 ` Marcin Wojtas
2017-08-28 21:14 ` Marcin Wojtas
2017-08-28 21:14 ` [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Marcin Wojtas
2017-08-28 21:14   ` Marcin Wojtas
2017-08-28 21:18   ` Geert Uytterhoeven
2017-08-28 21:18     ` Geert Uytterhoeven
2017-08-28 21:18     ` Geert Uytterhoeven
2017-08-28 21:54     ` Marcin Wojtas
2017-08-28 21:54       ` Marcin Wojtas
2017-08-28 21:54       ` Marcin Wojtas
2017-08-28 21:54       ` Marcin Wojtas
2017-08-28 23:24   ` Marek Vasut
2017-08-28 23:24     ` Marek Vasut
2017-08-29  7:40     ` Marcin Wojtas
2017-08-29  7:40       ` Marcin Wojtas
2017-09-04 16:26   ` Pavel Machek
2017-09-04 16:26     ` Pavel Machek
2017-08-28 21:14 ` [PATCH 2/2] arm64: dts: marvell: Force 3byte addressing mode for SPI on A7040 DB Marcin Wojtas
2017-08-28 21:14   ` Marcin Wojtas

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.