In some cases it is necessary to adjust the spi controller configuration before gpio cs is set. For example if spi devices requiring different cpol are used from the same controller the adjustment to cpol has to be made before gpio is activated. To achieve this set_cs should be executed before gpio cs and necessary adjustments can be made inside of controller driver. Suggested-by: Lukasz Zemla <Lukasz.Zemla@xxxxxxxxxxxx> Signed-off-by: Edmund Berenson <edmund.berenson@xxxxxxxxx> --- drivers/spi/spi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 5f9aedd1f0b6..bf2a67184969 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -976,6 +976,11 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) enable = !enable; if (spi->cs_gpiod) { + /* Some SPI masters need both GPIO CS & slave_select */ + if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && + spi->controller->set_cs) + spi->controller->set_cs(spi, !enable); + if (!(spi->mode & SPI_NO_CS)) { /* * Historically ACPI has no means of the GPIO polarity and @@ -993,10 +998,6 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) /* Polarity handled by GPIO library */ gpiod_set_value_cansleep(spi->cs_gpiod, activate); } - /* Some SPI masters need both GPIO CS & slave_select */ - if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && - spi->controller->set_cs) - spi->controller->set_cs(spi, !enable); } else if (spi->controller->set_cs) { spi->controller->set_cs(spi, !enable); } -- 2.37.4