]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
spi: core: allow defining time that cs is deasserted as a multiple of SCK
authorMartin Sperl <kernel@martin.sperl.org>
Sat, 23 Feb 2019 08:49:50 +0000 (08:49 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 8 May 2019 09:30:01 +0000 (18:30 +0900)
Support setting a delay between cs assert and deassert as
a multiple of spi clock length.

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c
include/linux/spi/spi.h

index 7e8ffe3fdc0084f434b8ae935c886309b98ff06c..cfa3c3decb8ade01a78a807c6596d1308dbb910c 100644 (file)
@@ -1111,6 +1111,7 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg,
 {
        u32 delay = xfer->cs_change_delay;
        u32 unit = xfer->cs_change_delay_unit;
+       u32 hz;
 
        /* return early on "fast" mode - for everything but USECS */
        if (!delay && unit != SPI_DELAY_UNIT_USECS)
@@ -1126,6 +1127,13 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg,
                break;
        case SPI_DELAY_UNIT_NSECS: /* nothing to do here */
                break;
+       case SPI_DELAY_UNIT_SCK:
+               /* if there is no effective speed know, then approximate
+                * by underestimating with half the requested hz
+                */
+               hz = xfer->effective_speed_hz ?: xfer->speed_hz / 2;
+               delay *= DIV_ROUND_UP(1000000000, hz);
+               break;
        default:
                dev_err_once(&msg->spi->dev,
                             "Use of unsupported delay unit %i, using default of 10us\n",
index 023beb9e9e4bc1c32c0bd390a777d333426cf31b..e552a036cb4d15a25e48a3bad9fa38c25ffd34d7 100644 (file)
@@ -831,6 +831,7 @@ struct spi_transfer {
        u8              cs_change_delay_unit;
 #define SPI_DELAY_UNIT_USECS   0
 #define SPI_DELAY_UNIT_NSECS   1
+#define SPI_DELAY_UNIT_SCK     2
        u32             speed_hz;
        u16             word_delay;