public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/3] spi-nor: intel-spi: Prefer WREN over other write enables
@ 2018-01-04  9:07 Mika Westerberg
  2018-01-04  9:07 ` [PATCH 2/3] spi-nor: intel-spi: Explicitly mark the driver as dangerous in Kconfig Mika Westerberg
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Mika Westerberg @ 2018-01-04  9:07 UTC (permalink / raw)
  To: linux-mtd
  Cc: Cyrille Pitchen, Marek Vasut, David Woodhouse, Brian Norris,
	Boris Brezillon, Richard Weinberger, Anthony Wong, Bin Meng,
	Mika Westerberg

On many older systems using SW sequencer the PREOP_OPTYPE register
contains two preopcodes as following:

  PREOP_OPTYPE=0xf2785006

The last two bytes are the opcodes decoded to:

  0x50 - Write enable for volatile status register
  0x06 - Write enable

The former is used to modify volatile bits in the status register. For
non-volatile bits the latter is needed. Preopcodes are used in SW
sequencer to send one command "atomically" without anything else
interfering the transfer. The sequence that gets executed is:

  - Send preopcode (write enable) from PREOP_OPTYPE register
  - Send the actual SPI command
  - Poll busy bit in the status register (0x05, RDSR)

Commit 8c473dd61bb5 ("spi-nor: intel-spi: Don't assume OPMENU0/1 to be
programmed by BIOS") enabled atomic sequence handling but because both
preopcodes are programmed, the following happens:

  if (preop >> 8)
  	val |= SSFSTS_CTL_SPOP;

Since on these systems preop >> 8 == 0x50 we end up picking volatile
write enable instead. Because of this the actual write command is pretty
much NOP unless there is a WREN latched in the chip already.

Fix this by preferring WREN over other write enable preopcodes.

Fixes: 8c473dd61bb5 ("spi-nor: intel-spi: Don't assume OPMENU0/1 to be programmed by BIOS")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: stable@vger.kernel.org
---
 drivers/mtd/spi-nor/intel-spi.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
index ef034d898a23..bba762aa0c8d 100644
--- a/drivers/mtd/spi-nor/intel-spi.c
+++ b/drivers/mtd/spi-nor/intel-spi.c
@@ -498,9 +498,17 @@ static int intel_spi_sw_cycle(struct intel_spi *ispi, u8 opcode, int len,
 	val |= SSFSTS_CTL_SCGO;
 	preop = readw(ispi->sregs + PREOP_OPTYPE);
 	if (preop) {
-		val |= SSFSTS_CTL_ACS;
-		if (preop >> 8)
-			val |= SSFSTS_CTL_SPOP;
+		switch (optype) {
+		case OPTYPE_WRITE_NO_ADDR:
+		case OPTYPE_WRITE_WITH_ADDR:
+			/*
+			 * For writes prefer WREN over other write enable
+			 * opcodes.
+			 */
+			val |= SSFSTS_CTL_ACS;
+			if ((preop >> 8) == SPINOR_OP_WREN)
+				val |= SSFSTS_CTL_SPOP;
+		}
 	}
 	writel(val, ispi->sregs + SSFSTS_CTL);
 
-- 
2.15.1

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

end of thread, other threads:[~2018-02-02  9:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-04  9:07 [PATCH 1/3] spi-nor: intel-spi: Prefer WREN over other write enables Mika Westerberg
2018-01-04  9:07 ` [PATCH 2/3] spi-nor: intel-spi: Explicitly mark the driver as dangerous in Kconfig Mika Westerberg
2018-01-07 20:32   ` Cyrille Pitchen
2018-01-07 21:06     ` Boris Brezillon
2018-01-08  4:02       ` Mika Westerberg
2018-01-08  4:00     ` Mika Westerberg
2018-01-04  9:07 ` [PATCH 3/3] spi-nor: intel-spi: Remove unused preopcodes field Mika Westerberg
2018-01-07 20:24   ` Cyrille Pitchen
2018-01-07 23:29 ` [PATCH 1/3] spi-nor: intel-spi: Prefer WREN over other write enables Cyrille Pitchen
2018-01-08  4:28   ` Mika Westerberg
2018-01-30 10:50 ` Mika Westerberg
2018-01-30 10:59   ` Boris Brezillon
2018-02-01 11:36 ` Cyrille Pitchen
2018-02-02  9:26   ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox