linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses
@ 2020-12-07 13:59 Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 1/4] " Tudor Ambarus
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tudor Ambarus @ 2020-12-07 13:59 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches,
	bugalski.piotr, linux-arm-kernel, linux-kernel, Tudor Ambarus

Starting with the move of the atmel-quadspi driver under SPI,
the following error could be seen when mounting a 16MByte ubifs:
UBIFS error (ubi0:0 pid 1893): check_lpt_type.constprop.6: invalid type (15) in LPT node type

1/4 fixes AHB accesses. The rest of the patches are small optimizations.
Tested on both sama5d2 and sam9x60.

Tudor Ambarus (4):
  spi: atmel-quadspi: Fix AHB memory accesses
  spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ
  spi: atmel-quadspi: Write QSPI_IAR only when needed
  spi: atmel-quadspi: Move common code outside of if else

 drivers/spi/atmel-quadspi.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

-- 
2.25.1


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

* [PATCH 1/4] spi: atmel-quadspi: Fix AHB memory accesses
  2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
@ 2020-12-07 13:59 ` Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 2/4] spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ Tudor Ambarus
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2020-12-07 13:59 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches,
	bugalski.piotr, linux-arm-kernel, linux-kernel, Tudor Ambarus,
	stable, Tom Burkart

Following error was seen when mounting a 16MByte ubifs:
UBIFS error (ubi0:0 pid 1893): check_lpt_type.constprop.6: invalid type (15) in LPT node type

QSPI_IFR.TFRTYP was not set correctly. When data transfer is enabled
and one wants to access the serial memory through AHB in order to:
 - read in the serial memory, but not a memory data, for example
   a JEDEC-ID, QSPI_IFR.TFRTYP must be written to '0' (both sama5d2
   and sam9x60).
 - read in the serial memory, and particularly a memory data,
   TFRTYP must be written to '1' (both sama5d2 and sam9x60).
 - write in the serial memory, but not a memory data, for example
   writing the configuration or the QSPI_SR, TFRTYP must be written
   to '2' for sama5d2 and to '0' for sam9x60.
 - write in the serial memory in particular to program a memory data,
   TFRTYP must be written to '3' for sama5d2 and to '1' for sam9x60.

Fix the setting of the QSPI_IFR.TFRTYP field.

Fixes: 2d30ac5ed633 ("mtd: spi-nor: atmel-quadspi: Use spi-mem interface for atmel-quadspi driver")
Cc: <stable@vger.kernel.org> # v5.0+
Reported-by: Tom Burkart <tom@aussec.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/spi/atmel-quadspi.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index b44521d4a245..ad913212426e 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -365,10 +365,14 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 	if (dummy_cycles)
 		ifr |= QSPI_IFR_NBDUM(dummy_cycles);
 
-	/* Set data enable */
-	if (op->data.nbytes)
+	/* Set data enable and data transfer type. */
+	if (op->data.nbytes) {
 		ifr |= QSPI_IFR_DATAEN;
 
+		if (op->addr.nbytes)
+			ifr |= QSPI_IFR_TFRTYP_MEM;
+	}
+
 	/*
 	 * If the QSPI controller is set in regular SPI mode, set it in
 	 * Serial Memory Mode (SMM).
@@ -393,7 +397,7 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 			atmel_qspi_write(icr, aq, QSPI_WICR);
 		atmel_qspi_write(ifr, aq, QSPI_IFR);
 	} else {
-		if (op->data.dir == SPI_MEM_DATA_OUT)
+		if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
 			ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
 
 		/* Set QSPI Instruction Frame registers */
-- 
2.25.1


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

* [PATCH 2/4] spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ
  2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 1/4] " Tudor Ambarus
@ 2020-12-07 13:59 ` Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 3/4] spi: atmel-quadspi: Write QSPI_IAR only when needed Tudor Ambarus
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2020-12-07 13:59 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches,
	bugalski.piotr, linux-arm-kernel, linux-kernel, Tudor Ambarus

That bit describes the APB transfer type. We are writing
serial memory registers via AHB acesses, that bit does not
make sense in the current context.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/spi/atmel-quadspi.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index ad913212426e..30533ab82c7b 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -386,9 +386,6 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 	(void)atmel_qspi_read(aq, QSPI_SR);
 
 	if (aq->caps->has_ricr) {
-		if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN)
-			ifr |= QSPI_IFR_APBTFRTYP_READ;
-
 		/* Set QSPI Instruction Frame registers */
 		atmel_qspi_write(iar, aq, QSPI_IAR);
 		if (op->data.dir == SPI_MEM_DATA_IN)
-- 
2.25.1


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

* [PATCH 3/4] spi: atmel-quadspi: Write QSPI_IAR only when needed
  2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 1/4] " Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 2/4] spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ Tudor Ambarus
@ 2020-12-07 13:59 ` Tudor Ambarus
  2020-12-07 13:59 ` [PATCH 4/4] spi: atmel-quadspi: Move common code outside of if else Tudor Ambarus
  2020-12-07 17:22 ` [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2020-12-07 13:59 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches,
	bugalski.piotr, linux-arm-kernel, linux-kernel, Tudor Ambarus

The address must be written in QSPI_IAR only when we have
a instruction frame with address but no data.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/spi/atmel-quadspi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index 30533ab82c7b..5fd0dc70bd74 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -385,9 +385,11 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 	/* Clear pending interrupts */
 	(void)atmel_qspi_read(aq, QSPI_SR);
 
-	if (aq->caps->has_ricr) {
-		/* Set QSPI Instruction Frame registers */
+	/* Set QSPI Instruction Frame registers. */
+	if (op->addr.nbytes && !op->data.nbytes)
 		atmel_qspi_write(iar, aq, QSPI_IAR);
+
+	if (aq->caps->has_ricr) {
 		if (op->data.dir == SPI_MEM_DATA_IN)
 			atmel_qspi_write(icr, aq, QSPI_RICR);
 		else
@@ -397,8 +399,6 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 		if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
 			ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
 
-		/* Set QSPI Instruction Frame registers */
-		atmel_qspi_write(iar, aq, QSPI_IAR);
 		atmel_qspi_write(icr, aq, QSPI_ICR);
 		atmel_qspi_write(ifr, aq, QSPI_IFR);
 	}
-- 
2.25.1


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

* [PATCH 4/4] spi: atmel-quadspi: Move common code outside of if else
  2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
                   ` (2 preceding siblings ...)
  2020-12-07 13:59 ` [PATCH 3/4] spi: atmel-quadspi: Write QSPI_IAR only when needed Tudor Ambarus
@ 2020-12-07 13:59 ` Tudor Ambarus
  2020-12-07 17:22 ` [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Tudor Ambarus @ 2020-12-07 13:59 UTC (permalink / raw)
  To: broonie, linux-spi
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches,
	bugalski.piotr, linux-arm-kernel, linux-kernel, Tudor Ambarus

QSPI_IFR is set as the last QSPI Instruction Frame register
regardless of the sama5d2 or sam9x60 version of the IP. Move
the writing of QSPI_IFR outside of the IP specific code.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 drivers/spi/atmel-quadspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index 5fd0dc70bd74..f4f3d5c9ce50 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -394,15 +394,15 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
 			atmel_qspi_write(icr, aq, QSPI_RICR);
 		else
 			atmel_qspi_write(icr, aq, QSPI_WICR);
-		atmel_qspi_write(ifr, aq, QSPI_IFR);
 	} else {
 		if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
 			ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
 
 		atmel_qspi_write(icr, aq, QSPI_ICR);
-		atmel_qspi_write(ifr, aq, QSPI_IFR);
 	}
 
+	atmel_qspi_write(ifr, aq, QSPI_IFR);
+
 	return 0;
 }
 
-- 
2.25.1


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

* Re: [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses
  2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
                   ` (3 preceding siblings ...)
  2020-12-07 13:59 ` [PATCH 4/4] spi: atmel-quadspi: Move common code outside of if else Tudor Ambarus
@ 2020-12-07 17:22 ` Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2020-12-07 17:22 UTC (permalink / raw)
  To: Tudor Ambarus, linux-spi
  Cc: ludovic.desroches, linux-arm-kernel, linux-kernel,
	alexandre.belloni, bugalski.piotr

On Mon, 7 Dec 2020 15:59:55 +0200, Tudor Ambarus wrote:
> Starting with the move of the atmel-quadspi driver under SPI,
> the following error could be seen when mounting a 16MByte ubifs:
> UBIFS error (ubi0:0 pid 1893): check_lpt_type.constprop.6: invalid type (15) in LPT node type
> 
> 1/4 fixes AHB accesses. The rest of the patches are small optimizations.
> Tested on both sama5d2 and sam9x60.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/4] spi: atmel-quadspi: Fix AHB memory accesses
      commit: cac8c821059639b015586abf61623c62cc549a13
[2/4] spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ
      commit: a6ff3a784ff9975dc77676827a2f448203511d19
[3/4] spi: atmel-quadspi: Write QSPI_IAR only when needed
      commit: d00364b6a60475cd75fd07e847ad6f955952638b
[4/4] spi: atmel-quadspi: Move common code outside of if else
      commit: c066efb07d1e8b801ea9d0727119958c9904e63d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2020-12-07 17:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 13:59 [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Tudor Ambarus
2020-12-07 13:59 ` [PATCH 1/4] " Tudor Ambarus
2020-12-07 13:59 ` [PATCH 2/4] spi: atmel-quadspi: Drop superfluous set of QSPI_IFR_APBTFRTYP_READ Tudor Ambarus
2020-12-07 13:59 ` [PATCH 3/4] spi: atmel-quadspi: Write QSPI_IAR only when needed Tudor Ambarus
2020-12-07 13:59 ` [PATCH 4/4] spi: atmel-quadspi: Move common code outside of if else Tudor Ambarus
2020-12-07 17:22 ` [PATCH 0/4] spi: atmel-quadspi: Fix AHB memory accesses Mark Brown

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).