From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Cc: 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>,
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,
Andreas Gnau <andreas.gnau@iopsys.eu>
Subject: Re: [PATCH 1/3] spi: airoha-snfi: en7523: workaround flash damaging if UART_TXD was short to GND
Date: Sat, 15 Nov 2025 17:01:19 +0100 [thread overview]
Message-ID: <aRijz3wMTGdmy2tq@lore-rh-laptop> (raw)
In-Reply-To: <20251114233431.1920015-2-mikhail.kshevetskiy@iopsys.eu>
[-- Attachment #1: Type: text/plain, Size: 3870 bytes --]
> 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 | 40 ++++++++++++++++++++++++++++++-----
> 1 file changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
> index 8408aee9c06e..0e84a9addfa5 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;
> @@ -1058,7 +1063,8 @@ 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;
here you can use bool for dma_enable:
bool dma_enable = true;
> + u32 sfc_strap;
>
> ctrl = devm_spi_alloc_host(dev, sizeof(*as_ctrl));
> if (!ctrl)
> @@ -1092,12 +1098,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));
> - if (err)
> - return err;
> + dma_enabled = 1;
> + if (device_is_compatible(dev, "airoha,en7523-snand")) {
> + 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;
dma_enable = false;
> + dev_warn(dev,
> + "=== WARNING ======================================================\n"
you do not need to add "WARNING here".
> + "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");
> + }
> + }
> +
> + 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;
nit: no need to add a new-line here:
ctrl->mem_ops = dma_enabled ? &airoha_snand_mem_ops
: &airoha_snand_nodma_mem_ops;
Regards,
Lorenzo
> ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
> ctrl->mode_bits = SPI_RX_DUAL;
> ctrl->setup = airoha_snand_setup;
> --
> 2.51.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-11-15 16:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 23:34 [PATCH 0/3] spi: airoha: add support of en7523 SoC (for 6.19) Mikhail Kshevetskiy
2025-11-14 23:34 ` [PATCH 1/3] spi: airoha-snfi: en7523: workaround flash damaging if UART_TXD was short to GND Mikhail Kshevetskiy
2025-11-15 16:01 ` Lorenzo Bianconi [this message]
2025-11-14 23:34 ` [PATCH 2/3] dt-bindings: spi: airoha: add compatible for EN7523 Mikhail Kshevetskiy
2025-11-14 23:34 ` [PATCH 3/3] arm: dts: airoha: en7523: add SNAND node Mikhail Kshevetskiy
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=aRijz3wMTGdmy2tq@lore-rh-laptop \
--to=lorenzo@kernel.org \
--cc=andreas.gnau@iopsys.eu \
--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=matthias.bgg@gmail.com \
--cc=mikhail.kshevetskiy@iopsys.eu \
--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