[PATCH] mtd: spi-nor: core: Introduce spi_nor_abort_octal_dtr()

Jaime Liao jaimeliao.tw at gmail.com
Wed Dec 6 23:51:47 PST 2023


From: JaimeLiao <jaimeliao at 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 at 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




More information about the linux-mtd mailing list