diff mbox series

[v3,3/6] spi: spi-gpio: Add support for MOSI idle state configuration

Message ID 8dcce41a69a89cb8ace2587ca7ddb1c665f2d1cb.1717539384.git.marcelo.schmitt@analog.com (mailing list archive)
State Superseded
Headers show
Series Add support for AD4000 series of ADCs | expand

Commit Message

Marcelo Schmitt June 4, 2024, 10:42 p.m. UTC
Implement MOSI idle low and MOSI idle high to better support peripherals
that request specific MOSI behavior.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 drivers/spi/spi-gpio.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Nuno Sá June 5, 2024, 9:26 a.m. UTC | #1
On Tue, 2024-06-04 at 19:42 -0300, Marcelo Schmitt wrote:
> Implement MOSI idle low and MOSI idle high to better support peripherals
> that request specific MOSI behavior.
> 
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> ---

Acked-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/spi/spi-gpio.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
> index 909cce109bba..d3b8c99f0cb4 100644
> --- a/drivers/spi/spi-gpio.c
> +++ b/drivers/spi/spi-gpio.c
> @@ -236,6 +236,14 @@ static void spi_gpio_chipselect(struct spi_device *spi,
> int is_active)
>  	}
>  }
>  
> +static void spi_gpio_set_mosi_idle(struct spi_device *spi)
> +{
> +	struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
> +
> +	gpiod_set_value_cansleep(spi_gpio->mosi,
> +				 !!(spi->mode & SPI_MOSI_IDLE_HIGH));
> +}
> +
>  static int spi_gpio_setup(struct spi_device *spi)
>  {
>  	struct gpio_desc	*cs;
> @@ -411,7 +419,8 @@ static int spi_gpio_probe(struct platform_device *pdev)
>  
>  	host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
>  	host->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL |
> -			    SPI_CS_HIGH | SPI_LSB_FIRST;
> +			  SPI_CS_HIGH | SPI_LSB_FIRST | SPI_MOSI_IDLE_LOW |
> +			  SPI_MOSI_IDLE_HIGH;
>  	if (!spi_gpio->mosi) {
>  		/* HW configuration without MOSI pin
>  		 *
> @@ -436,6 +445,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
>  	host->flags |= SPI_CONTROLLER_GPIO_SS;
>  	bb->chipselect = spi_gpio_chipselect;
>  	bb->set_line_direction = spi_gpio_set_direction;
> +	bb->set_mosi_idle = spi_gpio_set_mosi_idle;
>  
>  	if (host->flags & SPI_CONTROLLER_NO_TX) {
>  		bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0;
diff mbox series

Patch

diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 909cce109bba..d3b8c99f0cb4 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -236,6 +236,14 @@  static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
 	}
 }
 
+static void spi_gpio_set_mosi_idle(struct spi_device *spi)
+{
+	struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
+
+	gpiod_set_value_cansleep(spi_gpio->mosi,
+				 !!(spi->mode & SPI_MOSI_IDLE_HIGH));
+}
+
 static int spi_gpio_setup(struct spi_device *spi)
 {
 	struct gpio_desc	*cs;
@@ -411,7 +419,8 @@  static int spi_gpio_probe(struct platform_device *pdev)
 
 	host->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
 	host->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL |
-			    SPI_CS_HIGH | SPI_LSB_FIRST;
+			  SPI_CS_HIGH | SPI_LSB_FIRST | SPI_MOSI_IDLE_LOW |
+			  SPI_MOSI_IDLE_HIGH;
 	if (!spi_gpio->mosi) {
 		/* HW configuration without MOSI pin
 		 *
@@ -436,6 +445,7 @@  static int spi_gpio_probe(struct platform_device *pdev)
 	host->flags |= SPI_CONTROLLER_GPIO_SS;
 	bb->chipselect = spi_gpio_chipselect;
 	bb->set_line_direction = spi_gpio_set_direction;
+	bb->set_mosi_idle = spi_gpio_set_mosi_idle;
 
 	if (host->flags & SPI_CONTROLLER_NO_TX) {
 		bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0;