Skip to content

Commit 684a478

Browse files
ambarusbroonie
authored andcommitted
spi: Reintroduce spi_set_cs_timing()
commit 4ccf359 ("spi: remove spi_set_cs_timing()"), removed the method as noboby used it. Nobody used it probably because some SPI controllers use some default large cs-setup time that covers the usual cs-setup time required by the spi devices. There are though SPI controllers that have a smaller granularity for the cs-setup time and their default value can't fulfill the spi device requirements. That's the case for the at91 QSPI IPs where the default cs-setup time is half of the QSPI clock period. This was observed when using an sst26vf064b SPI NOR flash which needs a spi-cs-setup-ns = <7>; in order to be operated close to its maximum 104 MHz frequency. Call spi_set_cs_timing() in spi_setup() just before calling spi_set_cs(), as the latter needs the CS timings already set. If spi->controller->set_cs_timing is not set, the method will return 0. There's no functional impact expected for the existing drivers. Even if the spi-mt65xx.c and spi-tegra114.c drivers set the set_cs_timing method, there's no user for them as of now. The only tested user of this support will be a SPI NOR flash that comunicates with the Atmel QSPI controller for which the support follows in the next patches. One will notice that this support is a bit different from the one that was removed in commit 4ccf359 ("spi: remove spi_set_cs_timing()"), because this patch adapts to the changes done after the removal: the move of the cs delays to the spi device, the retirement of the lelgacy GPIO handling. The mutex handling was removed from spi_set_cs_timing() because we now always call spi_set_cs_timing() in spi_setup(), which already handles the spi->controller->io_mutex, so use the mutex handling from spi_setup(). Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Link: https://lore.kernel.org/r/20221117105249.115649-4-tudor.ambarus@microchip.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 33a2fde commit 684a478

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

drivers/spi/spi.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,37 @@ static int __spi_validate_bits_per_word(struct spi_controller *ctlr,
36213621
return 0;
36223622
}
36233623

3624+
/**
3625+
* spi_set_cs_timing - configure CS setup, hold, and inactive delays
3626+
* @spi: the device that requires specific CS timing configuration
3627+
*
3628+
* Return: zero on success, else a negative error code.
3629+
*/
3630+
static int spi_set_cs_timing(struct spi_device *spi)
3631+
{
3632+
struct device *parent = spi->controller->dev.parent;
3633+
int status = 0;
3634+
3635+
if (spi->controller->set_cs_timing && !spi->cs_gpiod) {
3636+
if (spi->controller->auto_runtime_pm) {
3637+
status = pm_runtime_get_sync(parent);
3638+
if (status < 0) {
3639+
pm_runtime_put_noidle(parent);
3640+
dev_err(&spi->controller->dev, "Failed to power device: %d\n",
3641+
status);
3642+
return status;
3643+
}
3644+
3645+
status = spi->controller->set_cs_timing(spi);
3646+
pm_runtime_mark_last_busy(parent);
3647+
pm_runtime_put_autosuspend(parent);
3648+
} else {
3649+
status = spi->controller->set_cs_timing(spi);
3650+
}
3651+
}
3652+
return status;
3653+
}
3654+
36243655
/**
36253656
* spi_setup - setup SPI mode and clock rate
36263657
* @spi: the device whose settings are being modified
@@ -3717,6 +3748,12 @@ int spi_setup(struct spi_device *spi)
37173748
}
37183749
}
37193750

3751+
status = spi_set_cs_timing(spi);
3752+
if (status) {
3753+
mutex_unlock(&spi->controller->io_mutex);
3754+
return status;
3755+
}
3756+
37203757
if (spi->controller->auto_runtime_pm && spi->controller->set_cs) {
37213758
status = pm_runtime_resume_and_get(spi->controller->dev.parent);
37223759
if (status < 0) {

0 commit comments

Comments
 (0)