Skip to content

Commit e976222

Browse files
committed
spi: STIG Mode Fixes for spi-cadence-qspi driver
Merge series from Dhruva Gole <[email protected]>: * Reset the CMD_CTRL Register, without which read/writes in STIG mode were failing in some cases. The issue came to light while using STIG Mode for small reads. * Also add a flag that can allow us to do direct reads but distinguish direct writes, thus enabling us to disable writes in DAC mode in some cases that require it. (Like to write to some connected Flash registers) * Fix register reads in STIG mode and also use STIG mode while reading flash registers. Currently if you try to read a register while in STIG mode there is no support for ADDR and thus naturally a register never gets read from the flash. This patch series has been tested on a TI AM625-SK-EVM with both a quad spi nor flash (s25hs) and OSPI NOR Flash (s28hs). Output of ltp-ddt test, "DD_RW_ERASESIZE_UBIFS" run with s25hs512t flash: ... [ 2.334068] spi-nor spi0.0: s25hs512t (65536 Kbytes) [ 2.339185] 7 fixed-partitions partitions found on MTD device fc40000.spi.0 [ 2.346158] Creating 7 MTD partitions on "fc40000.spi.0": [ 2.351555] 0x000000000000-0x000000080000 : "ospi.tiboot3" [ 2.358344] 0x000000080000-0x000000280000 : "ospi.tispl" [ 2.364788] 0x000000280000-0x000000680000 : "ospi.u-boot" [ 2.371311] 0x000000680000-0x0000006c0000 : "ospi.env" [ 2.377519] 0x0000006c0000-0x000000700000 : "ospi.env.backup" [ 2.384419] 0x000000800000-0x000003fc0000 : "ospi.rootfs" [ 2.390890] 0x000003fc0000-0x000004000000 : "ospi.phypattern" ..snip.. Test Start Time: Wed Jan 11 21:14:31 2023 ----------------------------------------- Testcase Result Exit Value -------- ------ ---------- OSPI_S_FUNC_DD_RW_ERASESIZE_UBIFS PASS 0 ----------------------------------------------- Total Tests: 1 Total Skipped Tests: 0 Total Failures: 0 Kernel Version: 6.2.0-rc1-00040-g700d796a94e0-dirty Machine Architecture: aarch64 Hostname: am62xx-evm
2 parents 7ec844a + d403fb6 commit e976222

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

drivers/spi/spi-cadence-quadspi.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct cqspi_st {
8484
u32 trigger_address;
8585
u32 wr_delay;
8686
bool use_direct_mode;
87+
bool use_direct_mode_wr;
8788
struct cqspi_flash_pdata f_pdata[CQSPI_MAX_CHIPSELECT];
8889
bool use_dma_read;
8990
u32 pd_dev_id;
@@ -531,6 +532,17 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
531532
/* 0 means 1 byte. */
532533
reg |= (((n_rx - 1) & CQSPI_REG_CMDCTRL_RD_BYTES_MASK)
533534
<< CQSPI_REG_CMDCTRL_RD_BYTES_LSB);
535+
536+
/* setup ADDR BIT field */
537+
if (op->addr.nbytes) {
538+
reg |= (0x1 << CQSPI_REG_CMDCTRL_ADDR_EN_LSB);
539+
reg |= ((op->addr.nbytes - 1) &
540+
CQSPI_REG_CMDCTRL_ADD_BYTES_MASK)
541+
<< CQSPI_REG_CMDCTRL_ADD_BYTES_LSB;
542+
543+
writel(op->addr.val, reg_base + CQSPI_REG_CMDADDRESS);
544+
}
545+
534546
status = cqspi_exec_flash_cmd(cqspi, reg);
535547
if (status)
536548
return status;
@@ -549,6 +561,9 @@ static int cqspi_command_read(struct cqspi_flash_pdata *f_pdata,
549561
memcpy(rxbuf, &reg, read_len);
550562
}
551563

564+
/* Reset CMD_CTRL Reg once command read completes */
565+
writel(0, reg_base + CQSPI_REG_CMDCTRL);
566+
552567
return 0;
553568
}
554569

@@ -613,7 +628,12 @@ static int cqspi_command_write(struct cqspi_flash_pdata *f_pdata,
613628
}
614629
}
615630

616-
return cqspi_exec_flash_cmd(cqspi, reg);
631+
ret = cqspi_exec_flash_cmd(cqspi, reg);
632+
633+
/* Reset CMD_CTRL Reg once command write completes */
634+
writel(0, reg_base + CQSPI_REG_CMDCTRL);
635+
636+
return ret;
617637
}
618638

619639
static int cqspi_read_setup(struct cqspi_flash_pdata *f_pdata,
@@ -937,6 +957,12 @@ static int cqspi_write_setup(struct cqspi_flash_pdata *f_pdata,
937957
reg = readl(reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
938958
reg |= CQSPI_REG_WR_DISABLE_AUTO_POLL;
939959
writel(reg, reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
960+
/*
961+
* DAC mode require auto polling as flash needs to be polled
962+
* for write completion in case of bubble in SPI transaction
963+
* due to slow CPU/DMA master.
964+
*/
965+
cqspi->use_direct_mode_wr = false;
940966
}
941967

942968
reg = readl(reg_base + CQSPI_REG_SIZE);
@@ -1222,7 +1248,7 @@ static ssize_t cqspi_write(struct cqspi_flash_pdata *f_pdata,
12221248
* data.
12231249
*/
12241250
if (!op->cmd.dtr && cqspi->use_direct_mode &&
1225-
((to + len) <= cqspi->ahb_size)) {
1251+
cqspi->use_direct_mode_wr && ((to + len) <= cqspi->ahb_size)) {
12261252
memcpy_toio(cqspi->ahb_base + to, buf, len);
12271253
return cqspi_wait_idle(cqspi);
12281254
}
@@ -1333,7 +1359,13 @@ static int cqspi_mem_process(struct spi_mem *mem, const struct spi_mem_op *op)
13331359
cqspi_configure(f_pdata, mem->spi->max_speed_hz);
13341360

13351361
if (op->data.dir == SPI_MEM_DATA_IN && op->data.buf.in) {
1336-
if (!op->addr.nbytes)
1362+
/*
1363+
* Performing reads in DAC mode forces to read minimum 4 bytes
1364+
* which is unsupported on some flash devices during register
1365+
* reads, prefer STIG mode for such small reads.
1366+
*/
1367+
if (!op->addr.nbytes ||
1368+
op->data.nbytes <= CQSPI_STIG_DATA_LEN_MAX)
13371369
return cqspi_command_read(f_pdata, op);
13381370

13391371
return cqspi_read(f_pdata, op);
@@ -1692,8 +1724,10 @@ static int cqspi_probe(struct platform_device *pdev)
16921724
cqspi->master_ref_clk_hz);
16931725
if (ddata->hwcaps_mask & CQSPI_SUPPORTS_OCTAL)
16941726
master->mode_bits |= SPI_RX_OCTAL | SPI_TX_OCTAL;
1695-
if (!(ddata->quirks & CQSPI_DISABLE_DAC_MODE))
1727+
if (!(ddata->quirks & CQSPI_DISABLE_DAC_MODE)) {
16961728
cqspi->use_direct_mode = true;
1729+
cqspi->use_direct_mode_wr = true;
1730+
}
16971731
if (ddata->quirks & CQSPI_SUPPORT_EXTERNAL_DMA)
16981732
cqspi->use_dma_read = true;
16991733
if (ddata->quirks & CQSPI_NO_SUPPORT_WR_COMPLETION)

0 commit comments

Comments
 (0)