* [PATCH v2 1/4] spi: cadence-quadspi: Flush posted register writes before INDAC access
2025-09-05 18:59 [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
@ 2025-09-05 18:59 ` Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 2/4] spi: cadence-quadspi: Flush posted register writes before DAC access Santhosh Kumar K
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-05 18:59 UTC (permalink / raw)
To: miquel.raynal, broonie, vigneshr, marex, computersforpeace,
theo.lebrun
Cc: linux-spi, linux-kernel, s-k6, praneeth, p-mantena, a-dutta,
u-kumar1, Pratyush Yadav, stable
From: Pratyush Yadav <pratyush@kernel.org>
cqspi_indirect_read_execute() and cqspi_indirect_write_execute() first
set the enable bit on APB region and then start reading/writing to the
AHB region. On TI K3 SoCs these regions lie on different endpoints. This
means that the order of the two operations is not guaranteed, and they
might be reordered at the interconnect level.
It is possible for the AHB write to be executed before the APB write to
enable the indirect controller, causing the transaction to be invalid
and the write erroring out. Read back the APB region write before
accessing the AHB region to make sure the write got flushed and the race
condition is eliminated.
Fixes: 140623410536 ("mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller")
CC: stable@vger.kernel.org
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
drivers/spi/spi-cadence-quadspi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 9bf823348cd3..eaf9a0f522d5 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -764,6 +764,7 @@ static int cqspi_indirect_read_execute(struct cqspi_flash_pdata *f_pdata,
reinit_completion(&cqspi->transfer_complete);
writel(CQSPI_REG_INDIRECTRD_START_MASK,
reg_base + CQSPI_REG_INDIRECTRD);
+ readl(reg_base + CQSPI_REG_INDIRECTRD); /* Flush posted write. */
while (remaining > 0) {
if (use_irq &&
@@ -1090,6 +1091,8 @@ static int cqspi_indirect_write_execute(struct cqspi_flash_pdata *f_pdata,
reinit_completion(&cqspi->transfer_complete);
writel(CQSPI_REG_INDIRECTWR_START_MASK,
reg_base + CQSPI_REG_INDIRECTWR);
+ readl(reg_base + CQSPI_REG_INDIRECTWR); /* Flush posted write. */
+
/*
* As per 66AK2G02 TRM SPRUHY8F section 11.15.5.3 Indirect Access
* Controller programming sequence, couple of cycles of
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 2/4] spi: cadence-quadspi: Flush posted register writes before DAC access
2025-09-05 18:59 [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 1/4] spi: cadence-quadspi: Flush posted register writes before INDAC access Santhosh Kumar K
@ 2025-09-05 18:59 ` Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 3/4] spi: cadence-quadspi: Fix cqspi_setup_flash() Santhosh Kumar K
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-05 18:59 UTC (permalink / raw)
To: miquel.raynal, broonie, vigneshr, marex, computersforpeace,
theo.lebrun
Cc: linux-spi, linux-kernel, s-k6, praneeth, p-mantena, a-dutta,
u-kumar1, Pratyush Yadav, stable
From: Pratyush Yadav <pratyush@kernel.org>
cqspi_read_setup() and cqspi_write_setup() program the address width as
the last step in the setup. This is likely to be immediately followed by
a DAC region read/write. On TI K3 SoCs the DAC region is on a different
endpoint from the register region. This means that the order of the two
operations is not guaranteed, and they might be reordered at the
interconnect level. It is possible that the DAC read/write goes through
before the address width update goes through. In this situation if the
previous command used a different address width the OSPI command is sent
with the wrong number of address bytes, resulting in an invalid command
and undefined behavior.
Read back the size register to make sure the write gets flushed before
accessing the DAC region.
Fixes: 140623410536 ("mtd: spi-nor: Add driver for Cadence Quad SPI Flash Controller")
CC: stable@vger.kernel.org
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
drivers/spi/spi-cadence-quadspi.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index eaf9a0f522d5..447a32a08a93 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -719,6 +719,7 @@ static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
reg |= (op->addr.nbytes - 1);
writel(reg, reg_base + CQSPI_REG_SIZE);
+ readl(reg_base + CQSPI_REG_SIZE); /* Flush posted write. */
return 0;
}
@@ -1063,6 +1064,7 @@ static int cqspi_write_setup(struct cqspi_flash_pdata *f_pdata,
reg &= ~CQSPI_REG_SIZE_ADDRESS_MASK;
reg |= (op->addr.nbytes - 1);
writel(reg, reg_base + CQSPI_REG_SIZE);
+ readl(reg_base + CQSPI_REG_SIZE); /* Flush posted write. */
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 3/4] spi: cadence-quadspi: Fix cqspi_setup_flash()
2025-09-05 18:59 [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 1/4] spi: cadence-quadspi: Flush posted register writes before INDAC access Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 2/4] spi: cadence-quadspi: Flush posted register writes before DAC access Santhosh Kumar K
@ 2025-09-05 18:59 ` Santhosh Kumar K
2025-09-05 18:59 ` [PATCH v2 4/4] spi: cadence-quadspi: Use BIT() macros where possible Santhosh Kumar K
2025-09-11 6:27 ` [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
4 siblings, 0 replies; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-05 18:59 UTC (permalink / raw)
To: miquel.raynal, broonie, vigneshr, marex, computersforpeace,
theo.lebrun
Cc: linux-spi, linux-kernel, s-k6, praneeth, p-mantena, a-dutta,
u-kumar1, stable, Pratyush Yadav
The 'max_cs' stores the largest chip select number. It should only
be updated when the current 'cs' is greater than existing 'max_cs'. So,
fix the condition accordingly.
Also, return failure if there are no flash device declared.
Fixes: 0f3841a5e115 ("spi: cadence-qspi: report correct number of chip-select")
CC: stable@vger.kernel.org
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Théo Lebrun <theo.lebrun@bootlin.com>
Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
drivers/spi/spi-cadence-quadspi.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 447a32a08a93..6627a3059ea3 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -1722,12 +1722,10 @@ static const struct spi_controller_mem_caps cqspi_mem_caps = {
static int cqspi_setup_flash(struct cqspi_st *cqspi)
{
- unsigned int max_cs = cqspi->num_chipselect - 1;
struct platform_device *pdev = cqspi->pdev;
struct device *dev = &pdev->dev;
struct cqspi_flash_pdata *f_pdata;
- unsigned int cs;
- int ret;
+ int ret, cs, max_cs = -1;
/* Get flash device data */
for_each_available_child_of_node_scoped(dev->of_node, np) {
@@ -1740,10 +1738,10 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
if (cs >= cqspi->num_chipselect) {
dev_err(dev, "Chip select %d out of range.\n", cs);
return -EINVAL;
- } else if (cs < max_cs) {
- max_cs = cs;
}
+ max_cs = max_t(int, cs, max_cs);
+
f_pdata = &cqspi->f_pdata[cs];
f_pdata->cqspi = cqspi;
f_pdata->cs = cs;
@@ -1753,6 +1751,11 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
return ret;
}
+ if (max_cs < 0) {
+ dev_err(dev, "No flash device declared\n");
+ return -ENODEV;
+ }
+
cqspi->num_chipselect = max_cs + 1;
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 4/4] spi: cadence-quadspi: Use BIT() macros where possible
2025-09-05 18:59 [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
` (2 preceding siblings ...)
2025-09-05 18:59 ` [PATCH v2 3/4] spi: cadence-quadspi: Fix cqspi_setup_flash() Santhosh Kumar K
@ 2025-09-05 18:59 ` Santhosh Kumar K
2025-09-11 6:27 ` [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
4 siblings, 0 replies; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-05 18:59 UTC (permalink / raw)
To: miquel.raynal, broonie, vigneshr, marex, computersforpeace,
theo.lebrun
Cc: linux-spi, linux-kernel, s-k6, praneeth, p-mantena, a-dutta,
u-kumar1
From: Vignesh Raghavendra <vigneshr@ti.com>
Convert few open coded bit shifts to BIT() macro for better readability.
No functional changes intended.
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
drivers/spi/spi-cadence-quadspi.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 6627a3059ea3..af253b86f1ab 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -335,7 +335,7 @@ static bool cqspi_is_idle(struct cqspi_st *cqspi)
{
u32 reg = readl(cqspi->iobase + CQSPI_REG_CONFIG);
- return reg & (1UL << CQSPI_REG_CONFIG_IDLE_LSB);
+ return reg & BIT(CQSPI_REG_CONFIG_IDLE_LSB);
}
static u32 cqspi_get_rd_sram_level(struct cqspi_st *cqspi)
@@ -571,7 +571,7 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
reg |= (dummy_clk & CQSPI_REG_CMDCTRL_DUMMY_MASK)
<< CQSPI_REG_CMDCTRL_DUMMY_LSB;
- reg |= (0x1 << CQSPI_REG_CMDCTRL_RD_EN_LSB);
+ reg |= BIT(CQSPI_REG_CMDCTRL_RD_EN_LSB);
/* 0 means 1 byte. */
reg |= (((n_rx - 1) & CQSPI_REG_CMDCTRL_RD_BYTES_MASK)
@@ -579,7 +579,7 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
/* setup ADDR BIT field */
if (op->addr.nbytes) {
- reg |= (0x1 << CQSPI_REG_CMDCTRL_ADDR_EN_LSB);
+ reg |= BIT(CQSPI_REG_CMDCTRL_ADDR_EN_LSB);
reg |= ((op->addr.nbytes - 1) &
CQSPI_REG_CMDCTRL_ADD_BYTES_MASK)
<< CQSPI_REG_CMDCTRL_ADD_BYTES_LSB;
@@ -646,7 +646,7 @@ static int cqspi_command_write(struct cqspi_flash_pdata *f_pdata,
reg = opcode << CQSPI_REG_CMDCTRL_OPCODE_LSB;
if (op->addr.nbytes) {
- reg |= (0x1 << CQSPI_REG_CMDCTRL_ADDR_EN_LSB);
+ reg |= BIT(CQSPI_REG_CMDCTRL_ADDR_EN_LSB);
reg |= ((op->addr.nbytes - 1) &
CQSPI_REG_CMDCTRL_ADD_BYTES_MASK)
<< CQSPI_REG_CMDCTRL_ADD_BYTES_LSB;
@@ -655,7 +655,7 @@ static int cqspi_command_write(struct cqspi_flash_pdata *f_pdata,
}
if (n_tx) {
- reg |= (0x1 << CQSPI_REG_CMDCTRL_WR_EN_LSB);
+ reg |= BIT(CQSPI_REG_CMDCTRL_WR_EN_LSB);
reg |= ((n_tx - 1) & CQSPI_REG_CMDCTRL_WR_BYTES_MASK)
<< CQSPI_REG_CMDCTRL_WR_BYTES_LSB;
data = 0;
@@ -1191,7 +1191,7 @@ static void cqspi_chipselect(struct cqspi_flash_pdata *f_pdata)
* CS2 to 4b'1011
* CS3 to 4b'0111
*/
- chip_select = 0xF & ~(1 << chip_select);
+ chip_select = 0xF & ~BIT(chip_select);
}
reg &= ~(CQSPI_REG_CONFIG_CHIPSELECT_MASK
@@ -1277,9 +1277,9 @@ static void cqspi_readdata_capture(struct cqspi_st *cqspi,
reg = readl(reg_base + CQSPI_REG_READCAPTURE);
if (bypass)
- reg |= (1 << CQSPI_REG_READCAPTURE_BYPASS_LSB);
+ reg |= BIT(CQSPI_REG_READCAPTURE_BYPASS_LSB);
else
- reg &= ~(1 << CQSPI_REG_READCAPTURE_BYPASS_LSB);
+ reg &= ~BIT(CQSPI_REG_READCAPTURE_BYPASS_LSB);
reg &= ~(CQSPI_REG_READCAPTURE_DELAY_MASK
<< CQSPI_REG_READCAPTURE_DELAY_LSB);
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] Miscellaneous fixes and clean-ups
2025-09-05 18:59 [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
` (3 preceding siblings ...)
2025-09-05 18:59 ` [PATCH v2 4/4] spi: cadence-quadspi: Use BIT() macros where possible Santhosh Kumar K
@ 2025-09-11 6:27 ` Santhosh Kumar K
2025-09-11 11:16 ` Mark Brown
4 siblings, 1 reply; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-11 6:27 UTC (permalink / raw)
To: miquel.raynal, broonie, vigneshr, marex, computersforpeace,
theo.lebrun
Cc: linux-spi, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1,
s-k6
Hello,
On 06/09/25 00:29, Santhosh Kumar K wrote:
> This series introduces some small but important fixes and cleanups in
> the Cadence QSPI Controller.
>
> Changes in v2:
> - Use max_t() instead of if case
> - Add a logic to return failure if there are no flash device declared.
> - Convert all the open coded bit shifts to BIT() macro
> - Link to v1: https://lore.kernel.org/linux-spi/20250904133130.3105736-1-s-k6@ti.com/T/#m2a5b6024ae6f147615e54e12688d8ceb5acc6228
>
> Tested on TI's AM62A SK and AM62P SK:
> Logs: https://gist.github.com/santhosh21/0d25767b58d9a1d9624f2c502dd8f36b
>
> Signed-off-by: Santhosh Kumar K s-k6@ti.com
Gentle ping on this!
Regards,
Santhosh.
>
> Pratyush Yadav (2):
> spi: cadence-quadspi: Flush posted register writes before INDAC access
> spi: cadence-quadspi: Flush posted register writes before DAC access
>
> Santhosh Kumar K (1):
> spi: cadence-quadspi: Fix cqspi_setup_flash()
>
> Vignesh Raghavendra (1):
> spi: cadence-quadspi: Use BIT() macros where possible
>
> drivers/spi/spi-cadence-quadspi.c | 34 +++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 13 deletions(-)
>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] Miscellaneous fixes and clean-ups
2025-09-11 6:27 ` [PATCH v2 0/4] Miscellaneous fixes and clean-ups Santhosh Kumar K
@ 2025-09-11 11:16 ` Mark Brown
2025-09-11 11:33 ` Santhosh Kumar K
0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2025-09-11 11:16 UTC (permalink / raw)
To: Santhosh Kumar K
Cc: miquel.raynal, vigneshr, marex, computersforpeace, theo.lebrun,
linux-spi, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1
[-- Attachment #1: Type: text/plain, Size: 858 bytes --]
On Thu, Sep 11, 2025 at 11:57:05AM +0530, Santhosh Kumar K wrote:
> Gentle ping on this!
Please don't send content free pings and please allow a reasonable time
for review. People get busy, go on holiday, attend conferences and so
on so unless there is some reason for urgency (like critical bug fixes)
please allow at least a couple of weeks for review. If there have been
review comments then people may be waiting for those to be addressed.
Sending content free pings adds to the mail volume (if they are seen at
all) which is often the problem and since they can't be reviewed
directly if something has gone wrong you'll have to resend the patches
anyway, so sending again is generally a better approach though there are
some other maintainers who like them - if in doubt look at how patches
for the subsystem are normally handled.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/4] Miscellaneous fixes and clean-ups
2025-09-11 11:16 ` Mark Brown
@ 2025-09-11 11:33 ` Santhosh Kumar K
0 siblings, 0 replies; 8+ messages in thread
From: Santhosh Kumar K @ 2025-09-11 11:33 UTC (permalink / raw)
To: Mark Brown
Cc: miquel.raynal, vigneshr, marex, computersforpeace, theo.lebrun,
linux-spi, linux-kernel, praneeth, p-mantena, a-dutta, u-kumar1,
s-k6
Hello Mark,
On 11/09/25 16:46, Mark Brown wrote:
> On Thu, Sep 11, 2025 at 11:57:05AM +0530, Santhosh Kumar K wrote:
>
>> Gentle ping on this!
>
> Please don't send content free pings and please allow a reasonable time
> for review. People get busy, go on holiday, attend conferences and so
> on so unless there is some reason for urgency (like critical bug fixes)
> please allow at least a couple of weeks for review. If there have been
> review comments then people may be waiting for those to be addressed.
>
> Sending content free pings adds to the mail volume (if they are seen at
> all) which is often the problem and since they can't be reviewed
> directly if something has gone wrong you'll have to resend the patches
> anyway, so sending again is generally a better approach though there are
> some other maintainers who like them - if in doubt look at how patches
> for the subsystem are normally handled.
I understand the concern, and apologies for the follow-up.
The first three patches already carry reviewed-by, and the fourth is
only a macro changes with no functional impact. Given that the merge
window is approaching, I thought it would be reasonable to send a gentle
reminder.
Regards,
Santhosh.
^ permalink raw reply [flat|nested] 8+ messages in thread