summaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2018-11-01 17:25:04 -0400
committerMark Brown <broonie@kernel.org>2018-11-07 11:15:49 -0500
commit5132b3d283710d196cd8af99b5585507e8b30709 (patch)
tree500502d0cf45af7a321790aa116e2871128ea216 /drivers/spi
parent651022382c7f8da46cb4872a545ee1da6d097d2a (diff)
spi: gpio: Support 3WIRE high-impedance turn-around
Some devices such as the TPO TPG110 display panel require a "high-impedance turn-around", in effect a clock cycle after switching the line from output to input mode. Support this in the GPIO driver to begin with. Other driver may implement it if they can, it is unclear if this can be achieved with anything else than GPIO bit-banging. Cc: Andrzej Hajda <a.hajda@samsung.com> Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-gpio.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 45973ee3ae11..a4aee26028cd 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -256,11 +256,29 @@ static int spi_gpio_setup(struct spi_device *spi)
256static int spi_gpio_set_direction(struct spi_device *spi, bool output) 256static int spi_gpio_set_direction(struct spi_device *spi, bool output)
257{ 257{
258 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 258 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
259 int ret;
259 260
260 if (output) 261 if (output)
261 return gpiod_direction_output(spi_gpio->mosi, 1); 262 return gpiod_direction_output(spi_gpio->mosi, 1);
262 else 263
263 return gpiod_direction_input(spi_gpio->mosi); 264 ret = gpiod_direction_input(spi_gpio->mosi);
265 if (ret)
266 return ret;
267 /*
268 * Send a turnaround high impedance cycle when switching
269 * from output to input. Theoretically there should be
270 * a clock delay here, but as has been noted above, the
271 * nsec delay function for bit-banged GPIO is simply
272 * {} because bit-banging just doesn't get fast enough
273 * anyway.
274 */
275 if (spi->mode & SPI_3WIRE_HIZ) {
276 gpiod_set_value_cansleep(spi_gpio->sck,
277 !(spi->mode & SPI_CPOL));
278 gpiod_set_value_cansleep(spi_gpio->sck,
279 !!(spi->mode & SPI_CPOL));
280 }
281 return 0;
264} 282}
265 283
266static void spi_gpio_cleanup(struct spi_device *spi) 284static void spi_gpio_cleanup(struct spi_device *spi)
@@ -410,7 +428,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
410 return status; 428 return status;
411 429
412 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); 430 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
413 master->mode_bits = SPI_3WIRE | SPI_CPHA | SPI_CPOL; 431 master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL;
414 master->flags = master_flags; 432 master->flags = master_flags;
415 master->bus_num = pdev->id; 433 master->bus_num = pdev->id;
416 /* The master needs to think there is a chipselect even if not connected */ 434 /* The master needs to think there is a chipselect even if not connected */