linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
To: Lorenzo Bianconi <lorenzo@kernel.org>,
	Ray Liu <ray.liu@airoha.com>, Mark Brown <broonie@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Andy Shevchenko <andy@kernel.org>,
	linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mediatek@lists.infradead.org
Cc: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
	Andreas Gnau <andreas.gnau@iopsys.eu>
Subject: [PATCH v7 15/17] spi: airoha-snfi: en7523: workaround flash damaging if UART_TXD was short to GND
Date: Fri, 10 Oct 2025 06:31:34 +0300	[thread overview]
Message-ID: <20251010033136.1475673-16-mikhail.kshevetskiy@iopsys.eu> (raw)
In-Reply-To: <20251010033136.1475673-1-mikhail.kshevetskiy@iopsys.eu>

We found that some serial console may pull TX line to GROUND during board
boot time. Airoha uses TX line as one of it's BOOT pins. This will lead
to booting in RESERVED boot mode.

It was found that some flashes operates incorrectly in RESERVED mode.
Micron and Skyhigh flashes are definitely affected by the issue,
Winbond flashes are NOT affected.

Details:
--------
DMA reading of odd pages on affected flashes operates incorrectly. Page
reading offset (start of the page) on hardware level is replaced by 0x10.
Thus results in incorrect data reading. Usage of UBI make things even
worse. Any attempt to access UBI leads to ubi damaging. As result OS loading
becomes impossible.

Non-DMA reading is OK.

This patch detects booting in reserved mode, turn off DMA and print big
fat warning.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
 drivers/spi/spi-airoha-snfi.c | 38 ++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index 058e08811210..0f4e4779ec35 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -1013,6 +1013,11 @@ static const struct spi_controller_mem_ops airoha_snand_mem_ops = {
 	.dirmap_write = airoha_snand_dirmap_write,
 };
 
+static const struct spi_controller_mem_ops airoha_snand_nodma_mem_ops = {
+	.supports_op = airoha_snand_supports_op,
+	.exec_op = airoha_snand_exec_op,
+};
+
 static int airoha_snand_setup(struct spi_device *spi)
 {
 	struct airoha_snand_ctrl *as_ctrl;
@@ -1059,7 +1064,10 @@ static int airoha_snand_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct spi_controller *ctrl;
 	void __iomem *base;
-	int err;
+	int err, dma_enabled;
+#if defined(CONFIG_ARM)
+	u32 sfc_strap;
+#endif
 
 	ctrl = devm_spi_alloc_host(dev, sizeof(*as_ctrl));
 	if (!ctrl)
@@ -1093,12 +1101,36 @@ static int airoha_snand_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(as_ctrl->spi_clk),
 				     "unable to get spi clk\n");
 
-	err = dma_set_mask(as_ctrl->dev, DMA_BIT_MASK(32));
+	dma_enabled = 1;
+#if defined(CONFIG_ARM)
+	err = regmap_read(as_ctrl->regmap_ctrl,
+			  REG_SPI_CTRL_SFC_STRAP, &sfc_strap);
 	if (err)
 		return err;
 
+	if (!(sfc_strap & 0x04)) {
+		dma_enabled = 0;
+		printk(KERN_WARNING "\n"
+			"=== WARNING ======================================================\n"
+			"Detected booting in RESERVED mode (UART_TXD was short to GND).\n"
+			"This mode is known for incorrect DMA reading of some flashes.\n"
+			"Usage of DMA for flash operations will be disabled to prevent data\n"
+			"damage. Unplug your serial console and power cycle the board\n"
+			"to boot with full performance.\n"
+			"==================================================================\n\n");
+	}
+#endif
+
+	if (dma_enabled) {
+		err = dma_set_mask(as_ctrl->dev, DMA_BIT_MASK(32));
+		if (err)
+			return err;
+	}
+
 	ctrl->num_chipselect = 2;
-	ctrl->mem_ops = &airoha_snand_mem_ops;
+	ctrl->mem_ops = dma_enabled ?
+				&airoha_snand_mem_ops :
+				&airoha_snand_nodma_mem_ops;
 	ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
 	ctrl->mode_bits = SPI_RX_DUAL;
 	ctrl->setup = airoha_snand_setup;
-- 
2.51.0


  parent reply	other threads:[~2025-10-10  3:32 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10  3:31 [PATCH v7 00/17] spi: airoha: driver fixes & improvements Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 01/17] spi: airoha: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 02/17] spi: airoha: remove unnecessary restriction length Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 03/17] spi: airoha: add support of dual/quad wires spi modes to exec_op() handler Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 04/17] spi: airoha: remove unnecessary switch to non-dma mode Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 05/17] spi: airoha: switch back to non-dma mode in the case of error Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 06/17] spi: airoha: fix reading/writing of flashes with more than one plane per lun Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 07/17] spi: airoha: unify dirmap read/write code Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 08/17] spi: airoha: support of dualio/quadio flash reading commands Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 09/17] spi: airoha: avoid setting of page/oob sizes in REG_SPI_NFI_PAGEFMT Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 10/17] spi: airoha: reduce the number of modification of REG_SPI_NFI_CNFG and REG_SPI_NFI_SECCUS_SIZE registers Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 11/17] spi: airoha: set custom sector size equal to flash page size Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 12/17] spi: airoha: avoid reading flash page settings from SNFI registers during driver startup Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 13/17] spi: airoha: buffer must be 0xff-ed before writing Mikhail Kshevetskiy
2025-10-10  3:31 ` [PATCH v7 14/17] spi: airoha-snfi: make compatible with EN7523 SoC Mikhail Kshevetskiy
2025-10-10  3:31 ` Mikhail Kshevetskiy [this message]
2025-10-10  3:31 ` [PATCH v7 16/17] dt-bindings: spi: airoha: add compatible for EN7523 Mikhail Kshevetskiy
2025-10-10 14:24   ` Conor Dooley
2025-10-10 14:57     ` Mikhail Kshevetskiy
2025-10-10 18:59       ` Rob Herring
2025-10-10 19:20         ` [PATCH v8 00/15] spi: airoha: driver fixes & improvements Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 01/15] spi: airoha: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 02/15] spi: airoha: remove unnecessary restriction length Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 03/15] spi: airoha: add support of dual/quad wires spi modes to exec_op() handler Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 04/15] spi: airoha: remove unnecessary switch to non-dma mode Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 05/15] spi: airoha: switch back to non-dma mode in the case of error Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 06/15] spi: airoha: fix reading/writing of flashes with more than one plane per lun Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 07/15] spi: airoha: unify dirmap read/write code Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 08/15] spi: airoha: support of dualio/quadio flash reading commands Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 09/15] spi: airoha: avoid setting of page/oob sizes in REG_SPI_NFI_PAGEFMT Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 10/15] spi: airoha: reduce the number of modification of REG_SPI_NFI_CNFG and REG_SPI_NFI_SECCUS_SIZE registers Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 11/15] spi: airoha: set custom sector size equal to flash page size Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 12/15] spi: airoha: avoid reading flash page settings from SNFI registers during driver startup Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 13/15] spi: airoha: buffer must be 0xff-ed before writing Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 14/15] spi: airoha-snfi: en7523: workaround flash damaging if UART_TXD was short to GND Mikhail Kshevetskiy
2025-10-10 19:20           ` [PATCH v8 15/15] arm: dts: airoha: en7523: add SNAND node Mikhail Kshevetskiy
2025-10-10 23:37             ` Krzysztof Kozlowski
2025-10-10 23:41             ` Krzysztof Kozlowski
2025-10-10 23:36           ` [PATCH v8 00/15] spi: airoha: driver fixes & improvements Krzysztof Kozlowski
2025-10-10  3:31 ` [PATCH v7 17/17] arm: dts: airoha: en7523: add SNAND node Mikhail Kshevetskiy
2025-10-10 19:32 ` [PATCH v7 00/17] spi: airoha: driver fixes & improvements Rob Herring (Arm)

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=20251010033136.1475673-16-mikhail.kshevetskiy@iopsys.eu \
    --to=mikhail.kshevetskiy@iopsys.eu \
    --cc=andreas.gnau@iopsys.eu \
    --cc=andy@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=ray.liu@airoha.com \
    --cc=robh@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).