public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: core: Introduce spi_nor_abort_octal_dtr()
@ 2023-12-07  7:51 Jaime Liao
  2023-12-11 10:51 ` Michael Walle
  0 siblings, 1 reply; 10+ messages in thread
From: Jaime Liao @ 2023-12-07  7:51 UTC (permalink / raw)
  To: linux-mtd, tudor.ambarus, pratyush, michael, miquel.raynal
  Cc: leoyu, jaimeliao

From: JaimeLiao <jaimeliao@mxic.com.tw>

Some flashes contains 8D_8D_8D information in SFDP but did not enter
octal DTR mode if conditions are not satisfied.
However, still carry the opcode and dummy cycle for the octal DTR
protocol.
So that spi_nor_abort_octal_dtr() could abort octal DTR capability
then recall spi_nor_select_read/pp() for re-select a suitable
protocol.

Signed-off-by: JaimeLiao <jaimeliao@mxic.com.tw>
---
 drivers/mtd/spi-nor/core.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 1c443fe568cf..7cefab1d29d5 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3083,6 +3083,29 @@ static int spi_nor_init_params(struct spi_nor *nor)
 	return spi_nor_late_init_params(nor);
 }
 
+/** spi_nor_abort_octal_dtr() - abort octal dtr capability
+ * @nor:                pointer to a 'struct spi_nor'
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int spi_nor_abort_octal_dtr(struct spi_nor *nor)
+{
+	int err;
+
+	/* Abort octal dtr capability and re-select read and pp */
+	nor->params->hwcaps.mask &= ~SNOR_HWCAPS_X_X_X_DTR;
+	err = spi_nor_select_read(nor, nor->params->hwcaps.mask);
+	if (err)
+		return err;
+
+	err = spi_nor_select_pp(nor, nor->params->hwcaps.mask);
+	if (err)
+		return err;
+
+	return 0;
+
+}
+
 /** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.
  * @nor:                 pointer to a 'struct spi_nor'
  * @enable:              whether to enable or disable Octal DTR
@@ -3094,14 +3117,14 @@ static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable)
 	int ret;
 
 	if (!nor->params->set_octal_dtr)
-		return 0;
+		return spi_nor_abort_octal_dtr(nor);
 
 	if (!(nor->read_proto == SNOR_PROTO_8_8_8_DTR &&
 	      nor->write_proto == SNOR_PROTO_8_8_8_DTR))
-		return 0;
+		return spi_nor_abort_octal_dtr(nor);
 
 	if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE))
-		return 0;
+		return spi_nor_abort_octal_dtr(nor);
 
 	ret = nor->params->set_octal_dtr(nor, enable);
 	if (ret)
-- 
2.25.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2024-01-29 13:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-07  7:51 [PATCH] mtd: spi-nor: core: Introduce spi_nor_abort_octal_dtr() Jaime Liao
2023-12-11 10:51 ` Michael Walle
2023-12-12  9:05   ` liao jaime
2023-12-12 13:37     ` Michael Walle
2023-12-13  2:37       ` liao jaime
2023-12-13  8:48         ` Michael Walle
2023-12-13  9:05           ` liao jaime
2023-12-13  9:10             ` Michael Walle
2023-12-13  9:16               ` liao jaime
2024-01-29 13:01         ` Pratyush Yadav

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