Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1647618

[PATCH 2/2] spi: use gpio_desc instead of numeric gpio

From Chris Packham <chris.packham@alliedtelesis.co.nz>
Newsgroups linux.kernel
Subject [PATCH 2/2] spi: use gpio_desc instead of numeric gpio
Date 2017-05-23 06:10 +0200
Message-ID <tK9iV-6tR-9@gated-at.bofh.it> (permalink)
References <tK9iV-6tR-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


By using a gpio_desc and gpiod_set_value() instead of a numeric gpio and
gpio_set_value() the gpio flags are taken into account. This is useful
when using a gpio chip-select to supplement a controllers native
chip-select.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---

Notes:
    My specific use-case is I have a board that uses the spi-orion driver but
    only has one CS pin available. In order to access two spi slave devices the
    board has a 1-of-2 decoder/demultiplexer which is driven via a gpio.
    
    The problem is that for one of the 2 slave devices the gpio level required
    is opposite to the chip-select so I can't simply specify "spi-cs-high".
    With this change I can flag the gpio as active low and the gpio subsystem
    takes care of the additional inversion required.

 drivers/spi/spi.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6f87fec409b5..b39c0f9956dd 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -725,7 +725,10 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
 		enable = !enable;
 
 	if (gpio_is_valid(spi->cs_gpio)) {
-		gpio_set_value(spi->cs_gpio, !enable);
+		struct gpio_desc *gpio = gpio_to_desc(spi->cs_gpio);
+
+		if (gpio)
+			gpiod_set_value(gpio, !enable);
 		/* Some SPI masters need both GPIO CS & slave_select */
 		if ((spi->master->flags & SPI_MASTER_GPIO_SS) &&
 		    spi->master->set_cs)
-- 
2.13.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 2/2] spi: use gpio_desc instead of numeric gpio Chris Packham <chris.packham@alliedtelesis.co.nz> - 2017-05-23 06:10 +0200
  Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-23 20:30 +0200
    Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio Chris Packham <Chris.Packham@alliedtelesis.co.nz> - 2017-05-23 22:50 +0200
      Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio Chris Packham <Chris.Packham@alliedtelesis.co.nz> - 2017-05-24 07:50 +0200
        Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio Mark Brown <broonie@kernel.org> - 2017-05-24 19:10 +0200
    Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio Mark Brown <broonie@kernel.org> - 2017-05-24 19:10 +0200
  Re: [PATCH 2/2] spi: use gpio_desc instead of numeric gpio kbuild test robot <lkp@intel.com> - 2017-05-24 04:30 +0200

csiph-web