Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1721966 > unrolled thread

[PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode

Started byMarcin Wojtas <mw@semihalf.com>
First post2017-08-28 23:20 +0200
Last post2017-09-04 18:30 +0200
Articles 6 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Marcin Wojtas <mw@semihalf.com> - 2017-08-28 23:20 +0200
    Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Geert Uytterhoeven <geert@linux-m68k.org> - 2017-08-28 23:20 +0200
      Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Marcin Wojtas <mw@semihalf.com> - 2017-08-29 00:00 +0200
    Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing  mode Marek Vasut <marek.vasut@gmail.com> - 2017-08-29 01:30 +0200
      Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Marcin Wojtas <mw@semihalf.com> - 2017-08-29 09:50 +0200
    Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing  mode Pavel Machek <pavel@ucw.cz> - 2017-09-04 18:30 +0200

#1721966 — [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode

FromMarcin Wojtas <mw@semihalf.com>
Date2017-08-28 23:20 +0200
Subject[PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
Message-ID<ujzBT-29X-1@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1721967

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2017-08-28 23:20 +0200
Message-ID<ujzBT-29X-9@gated-at.bofh.it>
In reply to#1721966
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

[toc] | [prev] | [next] | [standalone]


#1722019

FromMarcin Wojtas <mw@semihalf.com>
Date2017-08-29 00:00 +0200
Message-ID<ujAeC-2oT-19@gated-at.bofh.it>
In reply to#1721967
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

[toc] | [prev] | [next] | [standalone]


#1722054 — Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-08-29 01:30 +0200
SubjectRe: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
Message-ID<ujBDH-3mw-1@gated-at.bofh.it>
In reply to#1721966
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

[toc] | [prev] | [next] | [standalone]


#1722203

FromMarcin Wojtas <mw@semihalf.com>
Date2017-08-29 09:50 +0200
Message-ID<ujJrA-8de-21@gated-at.bofh.it>
In reply to#1722054
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

[toc] | [prev] | [next] | [standalone]


#1726168 — Re: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode

FromPavel Machek <pavel@ucw.cz>
Date2017-09-04 18:30 +0200
SubjectRe: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
Message-ID<um2q6-7L6-11@gated-at.bofh.it>
In reply to#1721966

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web