From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: broonie@kernel.org, andy.shevchenko@gmail.com,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
rmallon@gmail.com, shawnguo@kernel.org
Cc: linux@armlinux.org.uk, Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [RFC PATCH 1/5] spi: use gpio_desc instead of numeric gpio
Date: Thu, 25 May 2017 16:30:39 +1200 [thread overview]
Message-ID: <20170525043043.1930-2-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20170525043043.1930-1-chris.packham@alliedtelesis.co.nz>
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>
---
(I've included this in this series for context, ultimately it should not be
needed once everything is using gpio_desc)
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
next prev parent reply other threads:[~2017-05-25 4:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-25 4:30 [RFC PATCH 0/5] spi: moving to struct gpio_desc Chris Packham
2017-05-25 4:30 ` Chris Packham [this message]
2017-05-25 4:30 ` [RFC PATCH 2/5] ARM: ep93xx: add gpiod_lookup_table for spi chip-selects Chris Packham
2017-05-25 4:30 ` [RFC PATCH 3/5] ARM: imx: " Chris Packham
2017-05-25 4:30 ` [RFC PATCH 4/5] spi: core: convert spi_master to use gpio_desc Chris Packham
2017-05-25 4:30 ` [RFC PATCH 5/5] ARM: ep93xx: remove chipselect from ep93xx_spi_info Chris Packham
[not found] ` <20170525043043.1930-1-chris.packham-6g8wRflRTwXFdCa3tKVlE6U/zSkkHjvu@public.gmane.org>
2017-05-29 13:36 ` [RFC PATCH 0/5] spi: moving to struct gpio_desc Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170525043043.1930-2-chris.packham@alliedtelesis.co.nz \
--to=chris.packham@alliedtelesis.co.nz \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=rmallon@gmail.com \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).