From: Marcelo Schmitt <marcelo.schmitt@analog.com>
To: <broonie@kernel.org>, <lars@metafoo.de>,
<Michael.Hennerich@analog.com>, <jic23@kernel.org>,
<robh+dt@kernel.org>, <krzysztof.kozlowski+dt@linaro.org>,
<conor+dt@kernel.org>, <nuno.sa@analog.com>,
<dlechner@baylibre.com>, <marcelo.schmitt1@gmail.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 2/6] spi: bitbang: Implement support for MOSI idle state configuration
Date: Tue, 4 Jun 2024 19:42:21 -0300 [thread overview]
Message-ID: <811a2771d93c16b48fb37286e648a03171c8d2bc.1717539384.git.marcelo.schmitt@analog.com> (raw)
In-Reply-To: <cover.1717539384.git.marcelo.schmitt@analog.com>
Some SPI peripherals may require strict MOSI line state when the controller
is not clocking out data.
Implement support for MOSI idle state configuration (low or high) by
setting the data output line level on controller setup and after transfers.
Bitbang operations now call controller specific set_mosi_idle() call back
to set MOSI to its idle state.
The MOSI line is kept at its idle state if no tx buffer is provided.
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
drivers/spi/spi-bitbang.c | 24 ++++++++++++++++++++++++
include/linux/spi/spi_bitbang.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index ca5cc67555c5..3dee085d3570 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -63,21 +63,28 @@ static unsigned bitbang_txrx_8(
unsigned flags
)
{
+ struct spi_bitbang *bitbang;
unsigned bits = t->bits_per_word;
unsigned count = t->len;
const u8 *tx = t->tx_buf;
u8 *rx = t->rx_buf;
+ bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 0)) {
u8 word = 0;
if (tx)
word = *tx++;
+ else
+ word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
*rx++ = word;
count -= 1;
}
+ if (bitbang->set_mosi_idle)
+ bitbang->set_mosi_idle(spi);
+
return t->len - count;
}
@@ -92,21 +99,28 @@ static unsigned bitbang_txrx_16(
unsigned flags
)
{
+ struct spi_bitbang *bitbang;
unsigned bits = t->bits_per_word;
unsigned count = t->len;
const u16 *tx = t->tx_buf;
u16 *rx = t->rx_buf;
+ bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 1)) {
u16 word = 0;
if (tx)
word = *tx++;
+ else
+ word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFFFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
*rx++ = word;
count -= 2;
}
+ if (bitbang->set_mosi_idle)
+ bitbang->set_mosi_idle(spi);
+
return t->len - count;
}
@@ -121,21 +135,28 @@ static unsigned bitbang_txrx_32(
unsigned flags
)
{
+ struct spi_bitbang *bitbang;
unsigned bits = t->bits_per_word;
unsigned count = t->len;
const u32 *tx = t->tx_buf;
u32 *rx = t->rx_buf;
+ bitbang = spi_controller_get_devdata(spi->controller);
while (likely(count > 3)) {
u32 word = 0;
if (tx)
word = *tx++;
+ else
+ word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFFFFFFFF : 0;
word = txrx_word(spi, ns, word, bits, flags);
if (rx)
*rx++ = word;
count -= 4;
}
+ if (bitbang->set_mosi_idle)
+ bitbang->set_mosi_idle(spi);
+
return t->len - count;
}
@@ -211,6 +232,9 @@ int spi_bitbang_setup(struct spi_device *spi)
goto err_free;
}
+ if (bitbang->set_mosi_idle)
+ bitbang->set_mosi_idle(spi);
+
dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
return 0;
diff --git a/include/linux/spi/spi_bitbang.h b/include/linux/spi/spi_bitbang.h
index b930eca2ef7b..1a54b593c691 100644
--- a/include/linux/spi/spi_bitbang.h
+++ b/include/linux/spi/spi_bitbang.h
@@ -22,6 +22,7 @@ struct spi_bitbang {
#define BITBANG_CS_ACTIVE 1 /* normally nCS, active low */
#define BITBANG_CS_INACTIVE 0
+ void (*set_mosi_idle)(struct spi_device *spi);
/* txrx_bufs() may handle dma mapping for transfers that don't
* already have one (transfer.{tx,rx}_dma is zero), or use PIO
*/
--
2.43.0
next prev parent reply other threads:[~2024-06-04 22:42 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 22:40 [PATCH v3 0/6] Add support for AD4000 series of ADCs Marcelo Schmitt
2024-06-04 22:41 ` [PATCH v3 1/6] spi: Add SPI mode bit for MOSI idle state configuration Marcelo Schmitt
2024-06-05 9:14 ` Nuno Sá
2024-06-05 12:02 ` Mark Brown
2024-06-06 20:10 ` Marcelo Schmitt
2024-06-07 13:52 ` Mark Brown
2024-06-05 12:24 ` Mark Brown
2024-06-05 16:37 ` David Lechner
2024-06-05 17:04 ` Mark Brown
2024-06-06 22:08 ` Marcelo Schmitt
2024-06-07 13:51 ` Mark Brown
2024-06-06 19:57 ` Marcelo Schmitt
2024-06-07 13:50 ` Mark Brown
2024-06-07 14:55 ` Marcelo Schmitt
2024-06-04 22:42 ` Marcelo Schmitt [this message]
2024-06-05 9:30 ` [PATCH v3 2/6] spi: bitbang: Implement support " Nuno Sá
2024-06-04 22:42 ` [PATCH v3 3/6] spi: spi-gpio: Add " Marcelo Schmitt
2024-06-05 9:26 ` Nuno Sá
2024-06-04 22:43 ` [PATCH v3 4/6] spi: spi-axi-spi-engine: Add support for MOSI idle configuration Marcelo Schmitt
2024-06-05 9:25 ` Nuno Sá
2024-06-05 17:03 ` David Lechner
2024-06-06 6:51 ` Nuno Sá
2024-06-06 13:21 ` David Lechner
2024-06-06 21:31 ` Marcelo Schmitt
2024-06-07 7:15 ` Nuno Sá
2024-06-07 14:40 ` Marcelo Schmitt
2024-06-09 9:11 ` Jonathan Cameron
2024-06-04 22:43 ` [PATCH v3 5/6] dt-bindings: iio: adc: Add AD4000 Marcelo Schmitt
2024-06-05 17:14 ` Conor Dooley
2024-06-07 14:35 ` Marcelo Schmitt
2024-06-07 14:49 ` Conor Dooley
2024-06-05 9:31 ` [PATCH v3 0/6] Add support for AD4000 series of ADCs Nuno Sá
2024-06-05 11:19 ` Marcelo Schmitt
2024-06-05 11:14 ` [PATCH v3 6/6] iio: adc: Add support for AD4000 Marcelo Schmitt
2024-06-05 13:03 ` Nuno Sá
2024-06-09 9:23 ` Jonathan Cameron
2024-06-11 10:34 ` Andy Shevchenko
2024-06-11 17:05 ` Jonathan Cameron
2024-06-05 20:50 ` kernel test robot
2024-06-05 21:32 ` kernel test robot
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=811a2771d93c16b48fb37286e648a03171c8d2bc.1717539384.git.marcelo.schmitt@analog.com \
--to=marcelo.schmitt@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh+dt@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).