All of lore.kernel.org
 help / color / mirror / Atom feed
From: tkuw584924@gmail.com
To: u-boot@lists.denx.de
Cc: jagan@amarulasolutions.com, vigneshr@ti.com, p.yadav@ti.com,
	tkuw584924@gmail.com, Bacem.Daassi@infineon.com,
	Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
Subject: [PATCH v9 4/9] mtd: spi-nor-core: Add support for volatile QE bit
Date: Tue, 29 Jun 2021 15:00:59 +0900	[thread overview]
Message-ID: <b53e5d36dd1ac7474cdaf6537458188ec7258fb1.1624944246.git.Takahiro.Kuwano@infineon.com> (raw)
In-Reply-To: <cover.1624944246.git.Takahiro.Kuwano@infineon.com>

From: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Some of Spansion/Cypress chips support volatile version of configuration
registers and it is recommended to update volatile registers in the field
application due to a risk of the non-volatile registers corruption by
power interrupt. This patch adds a function to set Quad Enable bit in CFR1
volatile.

Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
---
Changes in v9:
  - Rebase on top of u-boot-spi/next

Changes in v8:
  - Define spansion_quad_enable_volatile() under CONFIG_SPI_FLASH_SPANSION

Changes in v7:
  - No change

Changes in v6:
  - No change

Changes in v5:
  - Fix register address calculation, 'base | offset' -> 'base + offset'

 drivers/mtd/spi/spi-nor-core.c | 55 ++++++++++++++++++++++++++++++++++
 include/linux/mtd/spi-nor.h    |  1 +
 2 files changed, 56 insertions(+)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 9e85f7d73e..2b72d65b0a 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1711,6 +1711,61 @@ static int macronix_quad_enable(struct spi_nor *nor)
 }
 #endif
 
+#ifdef CONFIG_SPI_FLASH_SPANSION
+/**
+ * spansion_quad_enable_volatile() - enable Quad I/O mode in volatile register.
+ * @nor:	pointer to a 'struct spi_nor'
+ * @addr_base:	base address of register (can be >0 in multi-die parts)
+ * @dummy:	number of dummy cycles for register read
+ *
+ * It is recommended to update volatile registers in the field application due
+ * to a risk of the non-volatile registers corruption by power interrupt. This
+ * function sets Quad Enable bit in CFR1 volatile.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int spansion_quad_enable_volatile(struct spi_nor *nor, u32 addr_base,
+					 u8 dummy)
+{
+	u32 addr = addr_base + SPINOR_REG_ADDR_CFR1V;
+
+	u8 cr;
+	int ret;
+
+	/* Check current Quad Enable bit value. */
+	ret = spansion_read_any_reg(nor, addr, dummy, &cr);
+	if (ret < 0) {
+		dev_dbg(nor->dev,
+			"error while reading configuration register\n");
+		return -EINVAL;
+	}
+
+	if (cr & CR_QUAD_EN_SPAN)
+		return 0;
+
+	cr |= CR_QUAD_EN_SPAN;
+
+	write_enable(nor);
+
+	ret = spansion_write_any_reg(nor, addr, cr);
+
+	if (ret < 0) {
+		dev_dbg(nor->dev,
+			"error while writing configuration register\n");
+		return -EINVAL;
+	}
+
+	/* Read back and check it. */
+	ret = spansion_read_any_reg(nor, addr, dummy, &cr);
+	if (ret || !(cr & CR_QUAD_EN_SPAN)) {
+		dev_dbg(nor->dev, "Spansion Quad bit not set\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND)
 /*
  * Write status Register and configuration register with 2 bytes
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 5bb06882ea..81df05fe84 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -125,6 +125,7 @@
 #define SPINOR_OP_CLSR		0x30	/* Clear status register 1 */
 #define SPINOR_OP_RDAR		0x65	/* Read any register */
 #define SPINOR_OP_WRAR		0x71	/* Write any register */
+#define SPINOR_REG_ADDR_CFR1V	0x00800002
 
 /* Used for Micron flashes only. */
 #define SPINOR_OP_RD_EVCR	0x65	/* Read EVCR register */
-- 
2.25.1


  parent reply	other threads:[~2021-06-29  6:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29  6:00 [PATCH v9 0/9] mtd: spi-nor: Add support for Cypress s25hl-t/s25hs-t tkuw584924
2021-06-29  6:00 ` [PATCH v9 1/9] mtd: spi-nor: Add Cypress manufacturer ID tkuw584924
2021-06-29 13:37   ` Jagan Teki
2021-06-30 12:02   ` Jagan Teki
2021-06-29  6:00 ` [PATCH v9 2/9] mtd: spi-nor-ids: Add Cypress s25hl-t/s25hs-t tkuw584924
2021-06-29 13:39   ` Jagan Teki
2021-06-29  6:00 ` [PATCH v9 3/9] mtd: spi-nor-core: Add support for Read/Write Any Register tkuw584924
2021-06-29 13:39   ` Jagan Teki
2021-06-29  6:00 ` tkuw584924 [this message]
2021-06-29 13:40   ` [PATCH v9 4/9] mtd: spi-nor-core: Add support for volatile QE bit Jagan Teki
2021-06-29  6:01 ` [PATCH v9 5/9] mtd: spi-nor-core: Add the ->ready() hook tkuw584924
2021-06-29 13:42   ` Jagan Teki
2021-06-29  6:01 ` [PATCH v9 6/9] mtd: spi-nor-core: Read status by Read Any Register tkuw584924
2021-06-29 13:43   ` Jagan Teki
2021-06-29  6:01 ` [PATCH v9 7/9] mtd: spi-nor-core: Add Cypress manufacturer ID in set_4byte tkuw584924
2021-06-29 13:43   ` Jagan Teki
2021-06-29  6:01 ` [PATCH v9 8/9] mtd: spi-nor-core: Add fixups for Cypress s25hl-t/s25hs-t tkuw584924
2021-06-29 13:45   ` Jagan Teki
2021-06-29  6:01 ` [PATCH v9 9/9] mtd: spi-nor-tiny: " tkuw584924
2021-06-29 13:45   ` Jagan Teki

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=b53e5d36dd1ac7474cdaf6537458188ec7258fb1.1624944246.git.Takahiro.Kuwano@infineon.com \
    --to=tkuw584924@gmail.com \
    --cc=Bacem.Daassi@infineon.com \
    --cc=Takahiro.Kuwano@infineon.com \
    --cc=jagan@amarulasolutions.com \
    --cc=p.yadav@ti.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.