linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcin Wojtas <mw@semihalf.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mtd@lists.infradead.org, linux-spi@vger.kernel.org
Cc: robh+dt@kernel.org, mark.rutland@arm.com, will.deacon@arm.com,
	cyrille.pitchen@wedev4u.fr, marek.vasut@gmail.com,
	broonie@kernel.org, thomas.petazzoni@free-electrons.com,
	gregory.clement@free-electrons.com, nadavh@marvell.com,
	neta@marvell.com, omrii@marvell.com, hannah@marvell.com,
	mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com
Subject: [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode
Date: Mon, 28 Aug 2017 23:14:13 +0200	[thread overview]
Message-ID: <1503954854-30963-2-git-send-email-mw@semihalf.com> (raw)
In-Reply-To: <1503954854-30963-1-git-send-email-mw@semihalf.com>

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

  reply	other threads:[~2017-08-28 21:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 21:14 [PATCH 0/2] SPI NOR - force 3byte addressing mode Marcin Wojtas
2017-08-28 21:14 ` Marcin Wojtas [this message]
2017-08-28 21:18   ` [PATCH 1/2] mtd: spi-nor: add an option to force 3byte adressing mode Geert Uytterhoeven
     [not found]     ` <CAMuHMdX0b=J9AuPAvdRXGGVXvc7f9n7TJ0_VKR13P05toq9REw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-08-28 21:54       ` Marcin Wojtas
2017-08-28 23:24   ` Marek Vasut
2017-08-29  7:40     ` Marcin Wojtas
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1503954854-30963-2-git-send-email-mw@semihalf.com \
    --to=mw@semihalf.com \
    --cc=broonie@kernel.org \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=gregory.clement@free-electrons.com \
    --cc=hannah@marvell.com \
    --cc=jaz@semihalf.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=nadavh@marvell.com \
    --cc=neta@marvell.com \
    --cc=omrii@marvell.com \
    --cc=robh+dt@kernel.org \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=tn@semihalf.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).