From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <david@lechnology.com>
Cc: linux-spi@vger.kernel.org, linux-iio@vger.kernel.org,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Mark Brown <broonie@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/4] spi: add software implementation for SPI_CS_WORD
Date: Sun, 16 Sep 2018 12:32:22 +0100 [thread overview]
Message-ID: <20180916123222.67136773@archlinux> (raw)
In-Reply-To: <20180913003920.30600-3-david@lechnology.com>
On Wed, 12 Sep 2018 19:39:18 -0500
David Lechner <david@lechnology.com> wrote:
> This adds a default software implementation for the SPI_CS_WORD flag for
> controllers that don't have such a feature.
>
> The SPI_CS_WORD flag indicates that the CS line should be toggled
> between each word sent, not just between each transfer. The
> implementation works by using existing functions to split transfers into
> one-word-sized transfers and sets the cs_change bit for each of the
> new transfers.
>
> Signed-off-by: David Lechner <david@lechnology.com>
Looks good to me but I'm not that familiar with this code..
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/spi/spi.c | 31 +++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 9da0bc5a036c..84518ed58872 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -2783,8 +2783,10 @@ int spi_setup(struct spi_device *spi)
> return -EINVAL;
> /* help drivers fail *cleanly* when they need options
> * that aren't supported with their current controller
> + * SPI_CS_WORD has a fallback software implementation,
> + * so it is ignored here.
> */
> - bad_bits = spi->mode & ~spi->controller->mode_bits;
> + bad_bits = spi->mode & ~(spi->controller->mode_bits | SPI_CS_WORD);
> ugly_bits = bad_bits &
> (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD);
> if (ugly_bits) {
> @@ -2838,6 +2840,33 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
> if (list_empty(&message->transfers))
> return -EINVAL;
>
> + /* If an SPI controller does not support toggling the CS line on each
> + * transfer (indicated by the SPI_CS_WORD flag), we can emulate it by
> + * splitting transfers into one-word transfers and ensuring that
> + * cs_change is set for each transfer.
> + */
> + if ((spi->mode & SPI_CS_WORD) && !(ctlr->mode_bits & SPI_CS_WORD)) {
> + size_t maxsize;
> + int ret;
> +
> + maxsize = (spi->bits_per_word + 7) / 8;
> +
> + /* spi_split_transfers_maxsize() requires message->spi */
> + message->spi = spi;
> +
> + ret = spi_split_transfers_maxsize(ctlr, message, maxsize,
> + GFP_KERNEL);
> + if (ret)
> + return ret;
> +
> + list_for_each_entry(xfer, &message->transfers, transfer_list) {
> + /* don't change cs_change on the last entry in the list */
> + if (list_is_last(&xfer->transfer_list, &message->transfers))
> + break;
> + xfer->cs_change = 1;
> + }
> + }
> +
> /* Half-duplex links include original MicroWire, and ones with
> * only one data pin like SPI_3WIRE (switches direction) or where
> * either MOSI or MISO is missing. They can also be caused by
next prev parent reply other threads:[~2018-09-16 11:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-13 0:39 [PATCH v2 0/4] spi: introduce SPI_CS_WORD mode flag David Lechner
2018-09-13 0:39 ` [PATCH v2 1/4] spi: add new SPI_CS_WORD flag David Lechner
2018-09-16 11:29 ` Jonathan Cameron
2018-09-13 0:39 ` [PATCH v2 2/4] spi: add software implementation for SPI_CS_WORD David Lechner
2018-09-16 11:32 ` Jonathan Cameron [this message]
2018-09-17 21:22 ` Applied "spi: add software implementation for SPI_CS_WORD" to the spi tree Mark Brown
2018-09-13 0:39 ` [PATCH v2 3/4] iio: adc: ti-ads7950: use SPI_CS_WORD to reduce CPU usage David Lechner
2018-09-16 11:41 ` Jonathan Cameron
2018-09-16 16:24 ` David Lechner
2018-09-17 8:33 ` Jonathan Cameron
2018-09-13 0:39 ` [PATCH v2 4/4] spi: spi-davinci: Add support for SPI_CS_WORD David Lechner
2018-09-13 13:44 ` Geert Uytterhoeven
2018-09-13 14:26 ` David Lechner
2018-09-17 21:18 ` Mark Brown
2018-09-17 21:17 ` [PATCH v2 0/4] spi: introduce SPI_CS_WORD mode flag 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=20180916123222.67136773@archlinux \
--to=jic23@kernel.org \
--cc=broonie@kernel.org \
--cc=david@lechnology.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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).