Skip to content

Commit f732646

Browse files
ambarusbroonie
authored andcommitted
spi: atmel-quadspi: Add support for configuring CS timing
The at91 QSPI IP uses a default value of half of the period of the QSPI clock period for the cs-setup time, which is not always enough, an example being the sst26vf064b SPI NOR flash which requires a minimum cs-setup time of 5 ns. It was observed that none of the at91 SoCs can fulfill the minimum CS setup time for the aforementioned flash, as they operate at high frequencies and half a period does not suffice for the required CS setup time. Add support for configuring the CS timing in the controller. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Link: https://lore.kernel.org/r/20221117105249.115649-5-tudor.ambarus@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 684a478 commit f732646

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

drivers/spi/atmel-quadspi.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,39 @@ static int atmel_qspi_setup(struct spi_device *spi)
510510
return 0;
511511
}
512512

513+
static int atmel_qspi_set_cs_timing(struct spi_device *spi)
514+
{
515+
struct spi_controller *ctrl = spi->master;
516+
struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
517+
unsigned long clk_rate;
518+
u32 cs_setup;
519+
int delay;
520+
int ret;
521+
522+
delay = spi_delay_to_ns(&spi->cs_setup, NULL);
523+
if (delay <= 0)
524+
return delay;
525+
526+
clk_rate = clk_get_rate(aq->pclk);
527+
if (!clk_rate)
528+
return -EINVAL;
529+
530+
cs_setup = DIV_ROUND_UP((delay * DIV_ROUND_UP(clk_rate, 1000000)),
531+
1000);
532+
533+
ret = pm_runtime_resume_and_get(ctrl->dev.parent);
534+
if (ret < 0)
535+
return ret;
536+
537+
aq->scr |= QSPI_SCR_DLYBS(cs_setup);
538+
atmel_qspi_write(aq->scr, aq, QSPI_SCR);
539+
540+
pm_runtime_mark_last_busy(ctrl->dev.parent);
541+
pm_runtime_put_autosuspend(ctrl->dev.parent);
542+
543+
return 0;
544+
}
545+
513546
static void atmel_qspi_init(struct atmel_qspi *aq)
514547
{
515548
/* Reset the QSPI controller */
@@ -555,6 +588,7 @@ static int atmel_qspi_probe(struct platform_device *pdev)
555588

556589
ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_DUAL | SPI_TX_QUAD;
557590
ctrl->setup = atmel_qspi_setup;
591+
ctrl->set_cs_timing = atmel_qspi_set_cs_timing;
558592
ctrl->bus_num = -1;
559593
ctrl->mem_ops = &atmel_qspi_mem_ops;
560594
ctrl->num_chipselect = 1;

0 commit comments

Comments
 (0)