From: Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Geert Uytterhoeven
<geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
Subject: [PATCH/RFC] spi: core: Fix logic mismatch in spi_master.set_cs()
Date: Tue, 14 Jan 2014 12:36:51 +0100 [thread overview]
Message-ID: <1389699411-29135-1-git-send-email-geert@linux-m68k.org> (raw)
From: Geert Uytterhoeven <geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
The documentation for spi_master.set_cs() says:
assert or deassert chip select, true to assert
i.e. its "enable" parameter uses assertion-level logic.
This does not match the implementation of spi_set_cs(), which calls
spi_master.set_cs() with the wanted logical value of the chip select line,
i.e. "false" to assert an active low chip select, and "true" to assert an
active high chip select.
Correct the implementation to use assertion-level logic.
For GPIO-based chip selects, active high chip selects are still handled in
spi_set_cs(), as this is a direct GPIO level.
For SPI controller-based chip selects, active high chip selects must be
handled by the SPI master driver, if supported (some SPI controllers have
configurable chip select polarity).
Signed-off-by: Geert Uytterhoeven <geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
---
drivers/spi/spi.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a86569e1f178..eb20169e84e8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -561,13 +561,12 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
static void spi_set_cs(struct spi_device *spi, bool enable)
{
- if (spi->mode & SPI_CS_HIGH)
- enable = !enable;
-
- if (spi->cs_gpio >= 0)
+ if (spi->cs_gpio >= 0) {
+ if (spi->mode & SPI_CS_HIGH)
+ enable = !enable;
gpio_set_value(spi->cs_gpio, !enable);
- else if (spi->master->set_cs)
- spi->master->set_cs(spi, !enable);
+ } else if (spi->master->set_cs)
+ spi->master->set_cs(spi, enable);
}
/*
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next reply other threads:[~2014-01-14 11:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-14 11:36 Geert Uytterhoeven [this message]
[not found] ` <1389699411-29135-1-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-14 12:52 ` [PATCH/RFC] spi: core: Fix logic mismatch in spi_master.set_cs() Mark Brown
[not found] ` <20140114125242.GE15567-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-14 13:23 ` Geert Uytterhoeven
[not found] ` <CAMuHMdVmSUh8yphZ4oPR=QYp5uMS9BXgPRVuwa19S9q7jWxxiQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-14 13:45 ` Mark Brown
2014-01-14 14:44 ` Geert Uytterhoeven
[not found] ` <CAMuHMdXEsNKRxYv8gh5sDzpg_QH2RmrjYhLhCZx0QCcRN+gdOg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-14 14:50 ` Mark Brown
[not found] ` <20140114145002.GR15567-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-14 15:18 ` Geert Uytterhoeven
[not found] ` <CAMuHMdVhmtA0ogEqu-jj8Kvii5CwV8qfHn+GzgQ9uFKzH7Ua6w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-17 18:03 ` Mark Brown
[not found] ` <20140117180304.GB17314-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-17 19:04 ` Geert Uytterhoeven
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=1389699411-29135-1-git-send-email-geert@linux-m68k.org \
--to=geert-td1emuhucqxl1znqvxdv9g@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.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