From: Tudor Ambarus <tudor.ambarus@microchip.com>
To: <p.yadav@ti.com>, <michael@walle.cc>
Cc: <miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>,
<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<nicolas.ferre@microchip.com>, <zhengxunli@mxic.com.tw>,
<jaimeliao@mxic.com.tw>,
Tudor Ambarus <tudor.ambarus@microchip.com>
Subject: [PATCH v6 7/7] mtd: spi-nor: macronix: Add support for mx66lm1g45g
Date: Wed, 9 Feb 2022 15:36:56 +0200 [thread overview]
Message-ID: <20220209133656.374903-8-tudor.ambarus@microchip.com> (raw)
In-Reply-To: <20220209133656.374903-1-tudor.ambarus@microchip.com>
mx66lm1g45g supports just 1-1-1, 8-8-8 and 8D-8D-8D modes. There are
versions of mx66lm1g45g which do not support SFDP, thus use
SPI_NOR_SKIP_SFDP. The RDID command issued through the octal peripheral
interface outputs data always in STR mode for whatever reason. Since
8D-8D-8S is not common, avoid reading the ID when enabling the octal dtr
mode. Instead, read back the CR2 to check if the switch was successful.
Tested in 1-1-1 and 8d-8d-8d modes using sama7g5 QSPI IP.
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
# cat /sys/devices/platform/soc/e080c000.spi/spi_master/spi1/spi1.0/spi-nor/jedec_id
c2853b
# cat /sys/devices/platform/soc/e080c000.spi/spi_master/spi1/spi1.0/spi-nor/manufacturer
macronix
# cat /sys/devices/platform/soc/e080c000.spi/spi_master/spi1/spi1.0/spi-nor/partname
mx66lm1g45g
# cat /sys/devices/platform/soc/e080c000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp
cat: can't open '/sys/devices/platform/soc/e080c000.spi/spi_master/spi1/spi1.0/spi-nor/sfdp': No such file or directory
drivers/mtd/spi-nor/macronix.c | 131 +++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 97dba1ae7fb1..31b2a9f34e03 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -8,6 +8,130 @@
#include "core.h"
+#define SPINOR_OP_READ_CR2 0x71 /* Read Configuration Register 2 */
+#define SPINOR_OP_WRITE_CR2 0x72 /* Write Configuration Register 2 */
+#define SPINOR_OP_MX_DTR_RD 0xee /* Octa DTR Read Opcode */
+
+#define SPINOR_REG_CR2_MODE_ADDR 0 /* Address of Mode Enable in CR2 */
+#define SPINOR_REG_CR2_DTR_OPI_ENABLE BIT(1) /* DTR OPI Enable */
+#define SPINOR_REG_CR2_SPI 0 /* SPI Enable */
+
+/**
+ * Macronix SPI NOR flash operations.
+ */
+#define SPI_NOR_MX_READ_CR2_OP(ndummy, buf, ndata) \
+ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_READ_CR2, 0), \
+ SPI_MEM_OP_ADDR(4, SPINOR_REG_CR2_MODE_ADDR, 0), \
+ SPI_MEM_OP_DUMMY(ndummy, 0), \
+ SPI_MEM_OP_DATA_IN(ndata, buf, 0))
+
+#define SPI_NOR_MX_WRITE_CR2_OP(buf, ndata) \
+ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRITE_CR2, 0), \
+ SPI_MEM_OP_ADDR(4, SPINOR_REG_CR2_MODE_ADDR, 0), \
+ SPI_MEM_OP_NO_DUMMY, \
+ SPI_MEM_OP_DATA_OUT(ndata, buf, 0))
+
+static int spi_nor_macronix_read_cr2(struct spi_nor *nor, u8 ndummy, void *sr,
+ unsigned int nbytes)
+{
+ struct spi_mem_op op = SPI_NOR_MX_READ_CR2_OP(ndummy, sr, nbytes);
+
+ spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
+ return spi_mem_exec_op(nor->spimem, &op);
+}
+
+static int spi_nor_macronix_write_cr2(struct spi_nor *nor, const void *sr,
+ unsigned int nbytes)
+{
+ struct spi_mem_op op = SPI_NOR_MX_WRITE_CR2_OP(sr, nbytes);
+ int ret;
+
+ spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
+ ret = spi_nor_write_enable(nor);
+ if (ret)
+ return ret;
+ return spi_mem_exec_op(nor->spimem, &op);
+}
+
+static int spi_nor_macronix_octal_dtr_en(struct spi_nor *nor)
+{
+ u8 *buf = nor->bouncebuf;
+ int i, ret;
+
+ buf[0] = SPINOR_REG_CR2_DTR_OPI_ENABLE;
+ ret = spi_nor_macronix_write_cr2(nor, buf, 1);
+ if (ret)
+ return ret;
+
+ /* Read flash ID to make sure the switch was successful. */
+ ret = spi_nor_read_id(nor, 4, 4, buf, SNOR_PROTO_8_8_8_DTR);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < nor->info->id_len; i++)
+ if (buf[i * 2] != nor->info->id[i])
+ return -EINVAL;
+ return 0;
+}
+
+static int spi_nor_macronix_octal_dtr_dis(struct spi_nor *nor)
+{
+ u8 *buf = nor->bouncebuf;
+ int ret;
+
+ /*
+ * One byte transactions are not allowed in 8D-8D-8D mode. mx66lm1g45g
+ * requires that undefined register addresses to keep their value
+ * unchanged. Its second CR2 byte value is not defined. Read the second
+ * byte value of CR2 so that we can write it back when disabling
+ * Octal DTR mode.
+ */
+ ret = spi_nor_macronix_read_cr2(nor, 4, buf, 2);
+ if (ret)
+ return ret;
+ /* Keep the value of buf[1] unchanged.*/
+ buf[0] = SPINOR_REG_CR2_SPI;
+
+ ret = spi_nor_macronix_write_cr2(nor, buf, 2);
+ if (ret)
+ return ret;
+
+ ret = spi_nor_read_id(nor, 0, 0, buf, nor->reg_proto);
+ if (ret)
+ return ret;
+
+ if (memcmp(buf, nor->info->id, nor->info->id_len)) {
+ dev_dbg(nor->dev, "Failed to disable 8D-8D-8D mode.\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int spi_nor_macronix_octal_dtr_enable(struct spi_nor *nor, bool enable)
+{
+ return enable ? spi_nor_macronix_octal_dtr_en(nor) :
+ spi_nor_macronix_octal_dtr_dis(nor);
+}
+
+static void mx66lm1g45g_late_init(struct spi_nor *nor)
+{
+ nor->params->octal_dtr_enable = spi_nor_macronix_octal_dtr_enable;
+
+ /* Set the Fast Read settings. */
+ nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR;
+ spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR],
+ 0, 20, SPINOR_OP_MX_DTR_RD,
+ SNOR_PROTO_8_8_8_DTR);
+
+ nor->cmd_ext_type = SPI_NOR_EXT_INVERT;
+ nor->params->rdsr_dummy = 4;
+ nor->params->rdsr_addr_nbytes = 4;
+}
+
+static struct spi_nor_fixups mx66lm1g45g_fixups = {
+ .late_init = mx66lm1g45g_late_init,
+};
+
static int
mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
const struct sfdp_parameter_header *bfpt_header,
@@ -100,6 +224,13 @@ static const struct flash_info macronix_parts[] = {
{ "mx66u2g45g", INFO(0xc2253c, 0, 64 * 1024, 4096)
NO_SFDP_FLAGS(SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)
FIXUP_FLAGS(SPI_NOR_4B_OPCODES) },
+ { "mx66lm1g45g", INFO(0xc2853b, 0, 64 * 1024, 2048)
+ NO_SFDP_FLAGS(SPI_NOR_SKIP_SFDP | SECT_4K |
+ SPI_NOR_OCTAL_DTR_READ | SPI_NOR_OCTAL_DTR_PP)
+ FIXUP_FLAGS(SPI_NOR_4B_OPCODES | SPI_NOR_IO_MODE_EN_VOLATILE |
+ SPI_NOR_SOFT_RESET)
+ .fixups = &mx66lm1g45g_fixups,
+ },
};
static void macronix_default_init(struct spi_nor *nor)
--
2.25.1
prev parent reply other threads:[~2022-02-09 13:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 13:36 [PATCH v6 0/7] mtd: spi-nor: Prepare core and add " Tudor Ambarus
2022-02-09 13:36 ` [PATCH v6 1/7] mtd: spi-nor: Rename method, s/spi_nor_match_id/spi_nor_match_name Tudor Ambarus
2022-03-21 11:53 ` Pratyush Yadav
2022-03-21 11:55 ` Pratyush Yadav
2022-02-09 13:36 ` [PATCH v6 2/7] mtd: spi-nor: Introduce spi_nor_match_id() Tudor Ambarus
2022-02-09 13:36 ` [PATCH v6 3/7] mtd: spi-nor: core: Use auto-detection only once Tudor Ambarus
2022-02-09 13:36 ` [PATCH v6 4/7] mtd: spi-nor: core: Introduce method for RDID op Tudor Ambarus
2022-02-09 13:36 ` [PATCH v6 5/7] mtd: spi-nor: manufacturers: Use spi_nor_read_id() core method Tudor Ambarus
2022-02-09 13:36 ` [PATCH v6 6/7] mtd: spi-nor: core: Introduce SPI_NOR_SOFT_RESET flash_info fixup_flag Tudor Ambarus
2022-02-09 13:36 ` Tudor Ambarus [this message]
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=20220209133656.374903-8-tudor.ambarus@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=jaimeliao@mxic.com.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=michael@walle.cc \
--cc=miquel.raynal@bootlin.com \
--cc=nicolas.ferre@microchip.com \
--cc=p.yadav@ti.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=zhengxunli@mxic.com.tw \
/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
all inboxes | Powered by JetHome®