diff mbox series

[v6,2/5] spi: spi-imx: add support for SPI_MOSI_IDLE_LOW mode bit

Message ID 20230524091948.41779-3-boerge.struempfel@gmail.com (mailing list archive)
State Superseded
Headers show
Series spi: add SPI_MOSI_IDLE_LOW mode bit | expand

Commit Message

Boerge Struempfel May 24, 2023, 9:19 a.m. UTC
By default, the spi-imx controller pulls the mosi line high, whenever it
is idle. This behaviour can be inverted per CS by setting the
corresponding DATA_CTL bit in the config register of the controller.

Also, since the controller mode-bits have to be touched anyways, the
SPI_CPOL and SPI_CPHA are replaced by the combined SPI_MODE_X_MASK flag.

Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
---
 drivers/spi/spi-imx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Frieder Schrempf May 24, 2023, 9:47 a.m. UTC | #1
On 24.05.23 11:19, Boerge Struempfel wrote:
> By default, the spi-imx controller pulls the mosi line high, whenever it
> is idle. This behaviour can be inverted per CS by setting the
> corresponding DATA_CTL bit in the config register of the controller.
> 
> Also, since the controller mode-bits have to be touched anyways, the
> SPI_CPOL and SPI_CPHA are replaced by the combined SPI_MODE_X_MASK flag.
> 
> Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>

Thanks for working on this! We used a similar downstream patch for
driving NeoPixels with i.MX. I'm happy to see a proper upstream solution.

I also have this Python module [1] around for using spidev to drive the
LEDs. It would be nice to see support for SPI_MOSI_IDLE_LOW in py-spidev
[2] so we could use it there. Though the latter looks a bit like it is
not properly maintained anymore.

[1] https://github.com/fschrempf/py-neopixel-spidev
[2] https://github.com/doceme/py-spidev

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Boerge Struempfel May 24, 2023, 11:42 a.m. UTC | #2
Am Mi., 24. Mai 2023 um 11:47 Uhr schrieb Frieder Schrempf
<frieder.schrempf@kontron.de>:
>
> On 24.05.23 11:19, Boerge Struempfel wrote:
> > By default, the spi-imx controller pulls the mosi line high, whenever it
> > is idle. This behaviour can be inverted per CS by setting the
> > corresponding DATA_CTL bit in the config register of the controller.
> >
> > Also, since the controller mode-bits have to be touched anyways, the
> > SPI_CPOL and SPI_CPHA are replaced by the combined SPI_MODE_X_MASK flag.
> >
> > Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
>
> Thanks for working on this! We used a similar downstream patch for
> driving NeoPixels with i.MX. I'm happy to see a proper upstream solution.
>

Thanks for your reply. I'm glad to see that there is an interest for this
and I'm not the only one, who is working with this.

> I also have this Python module [1] around for using spidev to drive the
> LEDs. It would be nice to see support for SPI_MOSI_IDLE_LOW in py-spidev
> [2] so we could use it there. Though the latter looks a bit like it is
> not properly maintained anymore.

The python modules looks interesting.

FYI: there is already another patch by Chuanhong Guo on the mailing
list, which implements a proper driver for neopixel leds. It also allows
to add them via DT and access them via sys-fs. It might be an
interesting upstream alternative for your python module if it gets
accepted.

https://lore.kernel.org/lkml/20221212045558.69602-1-gch981213@gmail.com/

>
> [1] https://github.com/fschrempf/py-neopixel-spidev
> [2] https://github.com/doceme/py-spidev
>
> Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

--
Kind Regards,
Börge Strümpfel
Mark Brown May 30, 2023, 12:46 p.m. UTC | #3
On Wed, May 24, 2023 at 11:19:45AM +0200, Boerge Struempfel wrote:
> By default, the spi-imx controller pulls the mosi line high, whenever it
> is idle. This behaviour can be inverted per CS by setting the
> corresponding DATA_CTL bit in the config register of the controller.

This doesn't apply against current code, please check and resend.
Boerge Struempfel May 30, 2023, 1:27 p.m. UTC | #4
Am Di., 30. Mai 2023 um 14:46 Uhr schrieb Mark Brown <broonie@kernel.org>:
>
> On Wed, May 24, 2023 at 11:19:45AM +0200, Boerge Struempfel wrote:
> > By default, the spi-imx controller pulls the mosi line high, whenever it
> > is idle. This behaviour can be inverted per CS by setting the
> > corresponding DATA_CTL bit in the config register of the controller.
>
> This doesn't apply against current code, please check and resend.

I wrote this patch against the current master and not the next/master.
I'll upload an adjusted patch version momentarily.
I'm sorry for the inconvenience.

--
Kind Regards,
Börge Strümpfel
diff mbox series

Patch

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 34e5f81ec431..1c4172fcba2d 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -281,6 +281,7 @@  static bool spi_imx_can_dma(struct spi_controller *controller, struct spi_device
 #define MX51_ECSPI_CONFIG_SCLKPOL(cs)	(1 << ((cs & 3) +  4))
 #define MX51_ECSPI_CONFIG_SBBCTRL(cs)	(1 << ((cs & 3) +  8))
 #define MX51_ECSPI_CONFIG_SSBPOL(cs)	(1 << ((cs & 3) + 12))
+#define MX51_ECSPI_CONFIG_DATACTL(cs)	(1 << ((cs & 3) + 16))
 #define MX51_ECSPI_CONFIG_SCLKCTL(cs)	(1 << ((cs & 3) + 20))
 
 #define MX51_ECSPI_INT		0x10
@@ -573,6 +574,11 @@  static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
 		cfg &= ~MX51_ECSPI_CONFIG_SCLKCTL(spi_get_chipselect(spi, 0));
 	}
 
+	if (spi->mode & SPI_MOSI_IDLE_LOW)
+		cfg |= MX51_ECSPI_CONFIG_DATACTL(spi_get_chipselect(spi, 0));
+	else
+		cfg &= ~MX51_ECSPI_CONFIG_DATACTL(spi_get_chipselect(spi, 0));
+
 	if (spi->mode & SPI_CS_HIGH)
 		cfg |= MX51_ECSPI_CONFIG_SSBPOL(spi_get_chipselect(spi, 0));
 	else
@@ -1743,7 +1749,8 @@  static int spi_imx_probe(struct platform_device *pdev)
 	spi_imx->controller->prepare_message = spi_imx_prepare_message;
 	spi_imx->controller->unprepare_message = spi_imx_unprepare_message;
 	spi_imx->controller->slave_abort = spi_imx_slave_abort;
-	spi_imx->controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
+	spi_imx->controller->mode_bits = SPI_MODE_X_MASK | SPI_CS_HIGH | SPI_NO_CS |
+					 SPI_MOSI_IDLE_LOW;
 
 	if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx) ||
 	    is_imx53_ecspi(spi_imx))