From: sashiko-bot@kernel.org
To: "Santhosh Kumar K" <s-k6@ti.com>
Cc: "Michael Walle" <mwalle@kernel.org>,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
"Richard Weinberger" <richard@nod.at>,
devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Pratyush Yadav" <pratyush@kernel.org>
Subject: Re: [PATCH v8 08/18] spi: cadence-quadspi: add PHY tuning support
Date: Fri, 21 Aug 2026 12:54:14 +0000 [thread overview]
Message-ID: <20260821125415.6B75D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260821114822.4040338-9-s-k6@ti.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The DDR PHY tuning search loops modify the TX loop variable after a successful pattern match but before exiting the loop, resulting in an incorrect TX coordinate being recorded.
- [High] The `execute_tuning` callback modifies controller registers and executes SPI transfers without acquiring the SPI bus lock or maintaining a continuous PM runtime reference.
- [Medium] Device tree `reg` property parsing incorrectly assumes a 32-bit offset.
--
--- Patch [8]: [PATCH v8 08/18] spi: cadence-quadspi: add PHY tuning support ---
commit dcb00c8fe3b55241aea74077e15b54f0457e2f13
Author: Santhosh Kumar K <s-k6@ti.com>
spi: cadence-quadspi: add PHY tuning support
This commit adds an execute_tuning callback for delay-line calibration in
Cadence QSPI controllers to enable high-speed operation. It performs sweeps
of rx_delay and tx_delay pairs to find the optimal operating point. The
feature is currently enabled for am654-based OSPI controllers.
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index 046fa5d69b0f7..5651320426b14 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
> @@ -1559,10 +1717,1590 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
> return spi_mem_default_supports_op(mem, op);
> }
>
> +static int cqspi_write_pattern_to_cache(struct cqspi_flash_pdata *f_pdata,
> + struct spi_mem *mem,
> + const struct spi_mem_op *write_op)
> +{
> + struct spi_controller *ctlr = mem->spi->controller;
> + struct device *dev = &f_pdata->cqspi->pdev->dev;
> + struct spi_mem_op op = *write_op;
> + int ret;
> +
> + op.max_freq = mem->spi->max_speed_hz;
> + op.data.nbytes = sizeof(phy_tuning_pattern);
> + op.data.buf.out = phy_tuning_pattern;
> +
> + ret = ctlr->mem_ops->exec_op(mem, &op);
[Severity: High]
Does this bypass the SPI bus lock? By directly invoking the unlocked
ctlr->mem_ops->exec_op() callback instead of the standard spi_mem_exec_op(),
could concurrent transfers to other chip selects interleave and corrupt the
tuning configuration?
> + if (ret) {
> + dev_err(dev, "Failed to write PHY pattern to cache: %d\n", ret);
> + return ret;
> + }
[ ... ]
> +static int cqspi_phy_tuning_ddr(struct cqspi_flash_pdata *f_pdata,
> + struct spi_mem *mem)
> +{
[ ... ]
> + /* Primary rxlow: Sweep TX window to find valid RX lower bound */
> +
> + rxlow.tx = CQSPI_PHY_TX_LOOKUP_LOW_START;
> + do {
> + dev_dbg(dev, "Searching for Golden Primary rxlow on TX = %d\n",
> + rxlow.tx);
> + rxlow.read_delay = CQSPI_PHY_INIT_RD;
> + ret = cqspi_find_rx_low_ddr(f_pdata, mem, &rxlow);
> + rxlow.tx += CQSPI_PHY_DDR_SEARCH_STEP;
[Severity: High]
Will this modify the TX loop variable even after a successful pattern match?
When cqspi_find_rx_low_ddr() returns 0 (success), the loop condition evaluates
to false and terminates. However, rxlow.tx is unconditionally incremented here
before exiting.
Does this mean the selected TX baseline is shifted by 4 taps from the optimal
value, degrading calibration accuracy?
> + } while (ret && rxlow.tx <= CQSPI_PHY_TX_LOOKUP_LOW_END);
> + if (ret)
> + goto out;
[ ... ]
> +static int cqspi_am654_ospi_execute_tuning(struct spi_mem *mem,
> + struct spi_mem_op *read_op,
> + struct spi_mem_op *write_op)
> +{
> + struct cqspi_st *cqspi =
> + spi_controller_get_devdata(mem->spi->controller);
> + struct cqspi_flash_pdata *f_pdata;
[ ... ]
> + if (read_op->cmd.dtr || read_op->addr.dtr || read_op->dummy.dtr ||
> + read_op->data.dtr) {
> + f_pdata->use_dqs = true;
> + cqspi_phy_pre_config(cqspi, f_pdata, false);
[Severity: High]
Are hardware registers modified here without holding a PM runtime reference?
The spi_mem_execute_tuning() helper does not acquire the controller's PM
runtime reference or the SPI bus lock. Calling cqspi_phy_pre_config() performs
raw memory-mapped register accesses (like CQSPI_REG_CONFIG) without calling
pm_runtime_resume_and_get() first.
Could this cause a synchronous bus fault if the hardware is runtime-suspended?
> + ret = cqspi_phy_tuning_ddr(f_pdata, mem);
> + } else {
> + f_pdata->use_dqs = false;
> + cqspi_phy_pre_config(cqspi, f_pdata, true);
> + ret = cqspi_phy_tuning_sdr(f_pdata, mem);
> + }
[ ... ]
> @@ -1588,9 +3326,12 @@ static int cqspi_of_get_flash_pdata(struct platform_device *pdev,
> return -ENXIO;
> }
>
> - if (of_property_read_u32(np, "spi-max-frequency", &f_pdata->clk_rate)) {
> - dev_err(&pdev->dev, "couldn't determine spi-max-frequency\n");
> - return -ENXIO;
> + part_np = of_parse_phandle(np, "spi-phy-pattern-partition", 0);
> + if (part_np) {
> + f_pdata->phy_pattern_partition_valid =
> + !of_property_read_u32_index(part_np, "reg", 0,
> + &f_pdata->phy_pattern_partition_offset);
[Severity: Medium]
Will this property read fail on platforms where the device tree uses 64-bit
addresses?
Using of_property_read_u32_index() for an address just grabs the first 32-bit
cell, which will evaluate to 0 if #address-cells = <2> is set.
Would it be safer to use of_property_read_u64() or standard DT address helpers
so the tuning pattern offset is parsed correctly?
> + of_node_put(part_np);
> }
>
> return 0;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260821114822.4040338-1-s-k6@ti.com?part=8
next prev parent reply other threads:[~2026-08-21 12:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 11:48 [PATCH v8 00/18] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 01/18] spi: dt-bindings: add spi-max-post-config-frequency-hz property Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 02/18] spi: dt-bindings: add spi-phy-pattern-partition property Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 03/18] spi: parse spi-max-post-config-frequency-hz into post_config_max_speed_hz Santhosh Kumar K
2026-08-21 12:12 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 04/18] spi: spi-mem: teach spi_mem_adjust_op_freq() about post-config ops Santhosh Kumar K
2026-08-21 12:23 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 05/18] spi: spi-mem: add execute_tuning callback and spi_mem_execute_tuning() Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 06/18] spi: cadence-quadspi: move cqspi_readdata_capture earlier Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 07/18] spi: cadence-quadspi: add DQS support to read data capture Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 08/18] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-08-21 12:54 ` sashiko-bot [this message]
2026-08-21 11:48 ` [PATCH v8 09/18] spi: cadence-quadspi: skip DDR PHY tuning for 2-byte-address ops (i2383) Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 10/18] spi: cadence-quadspi: refactor direct read path for PHY support Santhosh Kumar K
2026-08-21 13:15 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 11/18] spi: cadence-quadspi: enable PHY for direct reads Santhosh Kumar K
2026-08-21 13:31 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 12/18] spi: cadence-quadspi: enable PHY for indirect writes Santhosh Kumar K
2026-08-21 13:43 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 13/18] spi: cadence-quadspi: reprogram CS timing on every chip-select switch Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 14/18] spi: cadence-quadspi: reprogram PHY DLL on runtime resume Santhosh Kumar K
2026-08-21 13:58 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 15/18] mtd: spinand: extract variant ranking logic into spinand_op_find_best_variant() Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 16/18] mtd: spinand: negotiate optimal controller operating point before dirmap creation Santhosh Kumar K
2026-08-21 14:13 ` sashiko-bot
2026-08-21 11:48 ` [PATCH v8 17/18] mtd: spi-nor: extract read op template construction into helper Santhosh Kumar K
2026-08-21 11:48 ` [PATCH v8 18/18] mtd: spi-nor: run controller optimization before dirmap creation Santhosh Kumar K
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=20260821125415.6B75D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=robh@kernel.org \
--cc=s-k6@ti.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=takahiro.kuwano@infineon.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox