Skip to content

Commit c188739

Browse files
tlebbroonie
authored andcommitted
spi: cadence-qspi: add early busywait to cqspi_wait_for_bit()
Call readl_relaxed_poll_timeout() with no sleep at the start of cqspi_wait_for_bit(). If its short timeout expires, a sleeping readl_relaxed_poll_timeout() call takes the relay. The reason is to avoid hrtimer interrupts on the system. All read operations are expected to take less than 100µs. Signed-off-by: Théo Lebrun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1f257b9 commit c188739

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

drivers/spi/spi-cadence-quadspi.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct cqspi_driver_platdata {
120120
/* Operation timeout value */
121121
#define CQSPI_TIMEOUT_MS 500
122122
#define CQSPI_READ_TIMEOUT_MS 10
123+
#define CQSPI_BUSYWAIT_TIMEOUT_US 500
123124

124125
/* Runtime_pm autosuspend delay */
125126
#define CQSPI_AUTOSUSPEND_TIMEOUT 2000
@@ -298,13 +299,27 @@ struct cqspi_driver_platdata {
298299

299300
#define CQSPI_REG_VERSAL_DMA_VAL 0x602
300301

301-
static int cqspi_wait_for_bit(void __iomem *reg, const u32 mask, bool clr)
302+
static int cqspi_wait_for_bit(const struct cqspi_driver_platdata *ddata,
303+
void __iomem *reg, const u32 mask, bool clr,
304+
bool busywait)
302305
{
306+
u64 timeout_us = CQSPI_TIMEOUT_MS * USEC_PER_MSEC;
303307
u32 val;
304308

309+
if (busywait) {
310+
int ret = readl_relaxed_poll_timeout(reg, val,
311+
(((clr ? ~val : val) & mask) == mask),
312+
0, CQSPI_BUSYWAIT_TIMEOUT_US);
313+
314+
if (ret != -ETIMEDOUT)
315+
return ret;
316+
317+
timeout_us -= CQSPI_BUSYWAIT_TIMEOUT_US;
318+
}
319+
305320
return readl_relaxed_poll_timeout(reg, val,
306321
(((clr ? ~val : val) & mask) == mask),
307-
10, CQSPI_TIMEOUT_MS * 1000);
322+
10, timeout_us);
308323
}
309324

310325
static bool cqspi_is_idle(struct cqspi_st *cqspi)
@@ -434,8 +449,8 @@ static int cqspi_exec_flash_cmd(struct cqspi_st *cqspi, unsigned int reg)
434449
writel(reg, reg_base + CQSPI_REG_CMDCTRL);
435450

436451
/* Polling for completion. */
437-
ret = cqspi_wait_for_bit(reg_base + CQSPI_REG_CMDCTRL,
438-
CQSPI_REG_CMDCTRL_INPROGRESS_MASK, 1);
452+
ret = cqspi_wait_for_bit(cqspi->ddata, reg_base + CQSPI_REG_CMDCTRL,
453+
CQSPI_REG_CMDCTRL_INPROGRESS_MASK, 1, true);
439454
if (ret) {
440455
dev_err(&cqspi->pdev->dev,
441456
"Flash command execution timed out.\n");
@@ -790,8 +805,8 @@ static int cqspi_indirect_read_execute(struct cqspi_flash_pdata *f_pdata,
790805
}
791806

792807
/* Check indirect done status */
793-
ret = cqspi_wait_for_bit(reg_base + CQSPI_REG_INDIRECTRD,
794-
CQSPI_REG_INDIRECTRD_DONE_MASK, 0);
808+
ret = cqspi_wait_for_bit(cqspi->ddata, reg_base + CQSPI_REG_INDIRECTRD,
809+
CQSPI_REG_INDIRECTRD_DONE_MASK, 0, true);
795810
if (ret) {
796811
dev_err(dev, "Indirect read completion error (%i)\n", ret);
797812
goto failrd;
@@ -1091,8 +1106,8 @@ static int cqspi_indirect_write_execute(struct cqspi_flash_pdata *f_pdata,
10911106
}
10921107

10931108
/* Check indirect done status */
1094-
ret = cqspi_wait_for_bit(reg_base + CQSPI_REG_INDIRECTWR,
1095-
CQSPI_REG_INDIRECTWR_DONE_MASK, 0);
1109+
ret = cqspi_wait_for_bit(cqspi->ddata, reg_base + CQSPI_REG_INDIRECTWR,
1110+
CQSPI_REG_INDIRECTWR_DONE_MASK, 0, false);
10961111
if (ret) {
10971112
dev_err(dev, "Indirect write completion error (%i)\n", ret);
10981113
goto failwr;

0 commit comments

Comments
 (0)