spi: use gpio[d]_set_value_cansleep for setting chipselect GPIO

Message ID 20190209233825.2883-1-linus.walleij@linaro.org
State New
Headers show
Series
  • spi: use gpio[d]_set_value_cansleep for setting chipselect GPIO
Related show

Commit Message

Linus Walleij Feb. 9, 2019, 11:38 p.m.
From: Felix Fietkau <nbd@nbd.name>

Sleeping is safe inside spi_transfer_one_message, and some
GPIO chips are running on slow busses (such as I2C GPIO
expanders) and need to sleep for setting values.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
This patch was found in the OpenWrt tree, I adapted it for
my recent changes to the SPI core.
---
 drivers/spi/spi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 2f7176f07591..93986f879b09 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -786,9 +786,10 @@  static void spi_set_cs(struct spi_device *spi, bool enable)
 		 */
 		if (!(spi->mode & SPI_NO_CS)) {
 			if (spi->cs_gpiod)
-				gpiod_set_value(spi->cs_gpiod, !enable);
+				gpiod_set_value_cansleep(spi->cs_gpiod,
+							 !enable);
 			else
-				gpio_set_value(spi->cs_gpio, !enable);
+				gpio_set_value_cansleep(spi->cs_gpio, !enable);
 		}
 		/* Some SPI masters need both GPIO CS & slave_select */
 		if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&