linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
@ 2020-12-03 17:12 Максим Киселёв
  2020-12-03 17:50 ` Vladimir Oltean
  0 siblings, 1 reply; 4+ messages in thread
From: Максим Киселёв @ 2020-12-03 17:12 UTC (permalink / raw)
  To: Vladimir Oltean, Mark Brown, linux-spi, linux-kernel,
	Максим
	Киселёв,
	Maxim Kochetkov

From: Maxim Kiselev <bigunclemax@gmail.com>
Date: Thu, 3 Dec 2020 18:56:12 +0300
Subject: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support

This patch allows use of GPIO for the chip select.
Because dSPI controller can't send transactions without hardware chip
selects, so first unused native CS will be set in SPI_PUSHR_CMD_PCS

Signed-off-by: Maxim Kiselev <bigunclemax@gmail.com>
---
 drivers/spi/spi-fsl-dspi.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 028736687488..d5fba34de740 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -913,9 +913,14 @@ static int dspi_transfer_one_message(struct
spi_controller *ctlr,
         dspi->cur_transfer = transfer;
         dspi->cur_msg = message;
         dspi->cur_chip = spi_get_ctldata(spi);
+
+        if (spi->cs_gpiod)
+            gpiod_set_value(spi->cs_gpiod, 1);
+
         /* Prepare command word for CMD FIFO */
         dspi->tx_cmd = SPI_PUSHR_CMD_CTAS(0) |
-                   SPI_PUSHR_CMD_PCS(spi->chip_select);
+                   SPI_PUSHR_CMD_PCS(spi->cs_gpiod ?
+                         ctlr->unused_native_cs : spi->chip_select);
         if (list_is_last(&dspi->cur_transfer->transfer_list,
                  &dspi->cur_msg->transfers)) {
             /* Leave PCS activated after last transfer when
@@ -1240,6 +1245,7 @@ static int dspi_probe(struct platform_device *pdev)
     dspi->pdev = pdev;
     dspi->ctlr = ctlr;

+    ctlr->use_gpio_descriptors = true;
     ctlr->setup = dspi_setup;
     ctlr->transfer_one_message = dspi_transfer_one_message;
     ctlr->dev.of_node = pdev->dev.of_node;
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
  2020-12-03 17:12 [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support Максим Киселёв
@ 2020-12-03 17:50 ` Vladimir Oltean
  2020-12-03 18:50   ` Maksim Kiselev
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2020-12-03 17:50 UTC (permalink / raw)
  To: Максим
	Киселёв
  Cc: Mark Brown, linux-spi, linux-kernel, Maxim Kochetkov

Hi Maxim,

On Thu, Dec 03, 2020 at 08:12:19PM +0300, Максим Киселёв wrote:
> From: Maxim Kiselev <bigunclemax@gmail.com>
> Date: Thu, 3 Dec 2020 18:56:12 +0300
> Subject: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
> 
> This patch allows use of GPIO for the chip select.
> Because dSPI controller can't send transactions without hardware chip
> selects, so first unused native CS will be set in SPI_PUSHR_CMD_PCS

Are you sure?

From the reference manual:

SPIx_PUSHR bits 10–15 PCS:
Select which PCS signals are to be asserted for the transfer. Refer to
the chip-specific SPI information for the number of PCS signals used in
this chip.
0 Negate the PCS[x] signal.
1 Assert the PCS[x] signal.

And the definition is:

#define SPI_PUSHR_CMD_PCS(x)		(BIT(x) & GENMASK(5, 0))

Notice the BIT(x).

I expect that you can set the PCS to 0 and no hard chip select will
assert.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
  2020-12-03 17:50 ` Vladimir Oltean
@ 2020-12-03 18:50   ` Maksim Kiselev
  2020-12-04  1:05     ` Vladimir Oltean
  0 siblings, 1 reply; 4+ messages in thread
From: Maksim Kiselev @ 2020-12-03 18:50 UTC (permalink / raw)
  To: Vladimir Oltean; +Cc: Mark Brown, linux-spi, linux-kernel, Maxim Kochetkov

Hi Vladimir, thanks for the answer!

I must have missed these. In any case, I would like to add
functionality for using GPIO as CS. Because I have a board which
actually uses this. I'II check your solution and modify my patch.

чт, 3 дек. 2020 г. в 20:50, Vladimir Oltean <olteanv@gmail.com>:
>
> Hi Maxim,
>
> On Thu, Dec 03, 2020 at 08:12:19PM +0300, Максим Киселёв wrote:
> > From: Maxim Kiselev <bigunclemax@gmail.com>
> > Date: Thu, 3 Dec 2020 18:56:12 +0300
> > Subject: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
> >
> > This patch allows use of GPIO for the chip select.
> > Because dSPI controller can't send transactions without hardware chip
> > selects, so first unused native CS will be set in SPI_PUSHR_CMD_PCS
>
> Are you sure?
>
> From the reference manual:
>
> SPIx_PUSHR bits 10–15 PCS:
> Select which PCS signals are to be asserted for the transfer. Refer to
> the chip-specific SPI information for the number of PCS signals used in
> this chip.
> 0 Negate the PCS[x] signal.
> 1 Assert the PCS[x] signal.
>
> And the definition is:
>
> #define SPI_PUSHR_CMD_PCS(x)            (BIT(x) & GENMASK(5, 0))
>
> Notice the BIT(x).
>
> I expect that you can set the PCS to 0 and no hard chip select will
> assert.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support
  2020-12-03 18:50   ` Maksim Kiselev
@ 2020-12-04  1:05     ` Vladimir Oltean
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Oltean @ 2020-12-04  1:05 UTC (permalink / raw)
  To: Maksim Kiselev; +Cc: Mark Brown, linux-spi, linux-kernel, Maxim Kochetkov

On Thu, Dec 03, 2020 at 09:50:04PM +0300, Maksim Kiselev wrote:
> In any case, I would like to add functionality for using GPIO as CS.
> Because I have a board which actually uses this.

I have absolutely nothing to object to that.
But the patches should still be as clean as possible, though.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-04  1:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 17:12 [PATCH] spi: spi-fsl-dspi: Add GPIO chip select support Максим Киселёв
2020-12-03 17:50 ` Vladimir Oltean
2020-12-03 18:50   ` Maksim Kiselev
2020-12-04  1:05     ` Vladimir Oltean

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).