linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers
@ 2025-06-06 13:37 Félix Piédallu via B4 Relay
  2025-06-06 13:37 ` [PATCH 1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message Félix Piédallu via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Félix Piédallu via B4 Relay @ 2025-06-06 13:37 UTC (permalink / raw)
  To: Mark Brown, Louis Chauvet
  Cc: linux-spi, linux-kernel, Félix Piédallu,
	pascal.eberhard

These patches fix the behaviour of the SPI Chip Select of the OMAP2 MCSPI
driver used on TI SoCs.

The omap2-mcspi driver supports the use of multi mode (multichannel in TI
documentation). In this mode, the CS is asserted and deasserted by the
hardware.

The multi mode is disabled for messages when cs_change=0 for all transfers
(e.g when CS is kept asserted between transfers of a same message).

The multi mode also needs to be disabled for messages when cs_change=1 on the
last transfer (e.g when CS is kept asserted after the WHOLE message), and the
message right after.

Currently, that is not the case and it CS is deasserted by hardware when it
shouldn't.
This breaks peripheral drivers that send multiple messages with the CS asserted
in between.

Patch 1 ensures that multi mode is disabled when cs_change=1 on the last
transfer of the message.

Patch 2 ensures that multi mode is disable on a message following one with
cs_change=1 on the last transfer.

This is the case for the TPM TIS SPI driver that uses this logic for flow
control purposes.

Tested on an AM6442 platform with a TPM ST33HTPH2X32AHE4.

Signed-off-by: Félix Piédallu <felix.piedallu@non.se.com>
---
Félix Piédallu (2):
      spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message
      spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted

 drivers/spi/spi-omap2-mcspi.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
---
base-commit: c46b66be7eb595e66e93eda13149e0d4f90924ea
change-id: 20250606-cs_change_fix-bb51ac0f2bcb

Best regards,
-- 
Félix Piédallu <felix.piedallu@non.se.com>



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

* [PATCH 1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message
  2025-06-06 13:37 [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Félix Piédallu via B4 Relay
@ 2025-06-06 13:37 ` Félix Piédallu via B4 Relay
  2025-06-06 13:37 ` [PATCH 2/2] spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted Félix Piédallu via B4 Relay
  2025-06-09 19:33 ` [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Félix Piédallu via B4 Relay @ 2025-06-06 13:37 UTC (permalink / raw)
  To: Mark Brown, Louis Chauvet
  Cc: linux-spi, linux-kernel, Félix Piédallu,
	pascal.eberhard

From: Félix Piédallu <felix.piedallu@non.se.com>

When the last transfer of a SPI message has the cs_change flag, the CS is kept
asserted after the message.
Multi-mode can't respect this as CS is deasserted by the hardware at the end of
the message.

Disable multi-mode when not applicable to the current message.

Fixes: d153ff4056cb ("spi: omap2-mcspi: Add support for MULTI-mode")
Signed-off-by: Félix Piédallu <felix.piedallu@non.se.com>
---
 drivers/spi/spi-omap2-mcspi.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 532b2e9c31d0d..05766b98de36f 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -1287,9 +1287,15 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr,
 			mcspi->use_multi_mode = false;
 		}
 
-		/* Check if transfer asks to change the CS status after the transfer */
-		if (!tr->cs_change)
-			mcspi->use_multi_mode = false;
+		if (list_is_last(&tr->transfer_list, &msg->transfers)) {
+			/* Check if transfer asks to keep the CS status after the whole message */
+			if (tr->cs_change)
+				mcspi->use_multi_mode = false;
+		} else {
+			/* Check if transfer asks to change the CS status after the transfer */
+			if (!tr->cs_change)
+				mcspi->use_multi_mode = false;
+		}
 
 		/*
 		 * If at least one message is not compatible, switch back to single mode

-- 
2.43.0



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

* [PATCH 2/2] spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted
  2025-06-06 13:37 [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Félix Piédallu via B4 Relay
  2025-06-06 13:37 ` [PATCH 1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message Félix Piédallu via B4 Relay
@ 2025-06-06 13:37 ` Félix Piédallu via B4 Relay
  2025-06-09 19:33 ` [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Félix Piédallu via B4 Relay @ 2025-06-06 13:37 UTC (permalink / raw)
  To: Mark Brown, Louis Chauvet
  Cc: linux-spi, linux-kernel, Félix Piédallu,
	pascal.eberhard

From: Félix Piédallu <felix.piedallu@non.se.com>

When the last transfer of a SPI message has the cs_change flag, the CS is kept
asserted after the message.
The next message can't use multi-mode because the CS will be briefly deasserted
before the first transfer.

Remove the early exit of the list_for_each_entry because the last transfer
actually needs to be always checked.

Fixes: d153ff4056cb ("spi: omap2-mcspi: Add support for MULTI-mode")
Signed-off-by: Félix Piédallu <felix.piedallu@non.se.com>
---
 drivers/spi/spi-omap2-mcspi.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 05766b98de36f..4c5f12b76de6a 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -134,6 +134,7 @@ struct omap2_mcspi {
 	size_t			max_xfer_len;
 	u32			ref_clk_hz;
 	bool			use_multi_mode;
+	bool			last_msg_kept_cs;
 };
 
 struct omap2_mcspi_cs {
@@ -1269,6 +1270,10 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr,
 	 * multi-mode is applicable.
 	 */
 	mcspi->use_multi_mode = true;
+
+	if (mcspi->last_msg_kept_cs)
+		mcspi->use_multi_mode = false;
+
 	list_for_each_entry(tr, &msg->transfers, transfer_list) {
 		if (!tr->bits_per_word)
 			bits_per_word = msg->spi->bits_per_word;
@@ -1289,22 +1294,17 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr,
 
 		if (list_is_last(&tr->transfer_list, &msg->transfers)) {
 			/* Check if transfer asks to keep the CS status after the whole message */
-			if (tr->cs_change)
+			if (tr->cs_change) {
 				mcspi->use_multi_mode = false;
+				mcspi->last_msg_kept_cs = true;
+			} else {
+				mcspi->last_msg_kept_cs = false;
+			}
 		} else {
 			/* Check if transfer asks to change the CS status after the transfer */
 			if (!tr->cs_change)
 				mcspi->use_multi_mode = false;
 		}
-
-		/*
-		 * If at least one message is not compatible, switch back to single mode
-		 *
-		 * The bits_per_word of certain transfer can be different, but it will have no
-		 * impact on the signal itself.
-		 */
-		if (!mcspi->use_multi_mode)
-			break;
 	}
 
 	omap2_mcspi_set_mode(ctlr);

-- 
2.43.0



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

* Re: [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers
  2025-06-06 13:37 [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Félix Piédallu via B4 Relay
  2025-06-06 13:37 ` [PATCH 1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message Félix Piédallu via B4 Relay
  2025-06-06 13:37 ` [PATCH 2/2] spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted Félix Piédallu via B4 Relay
@ 2025-06-09 19:33 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-06-09 19:33 UTC (permalink / raw)
  To: Louis Chauvet, Félix Piédallu
  Cc: linux-spi, linux-kernel, pascal.eberhard

On Fri, 06 Jun 2025 15:37:23 +0200, Félix Piédallu wrote:
> These patches fix the behaviour of the SPI Chip Select of the OMAP2 MCSPI
> driver used on TI SoCs.
> 
> The omap2-mcspi driver supports the use of multi mode (multichannel in TI
> documentation). In this mode, the CS is asserted and deasserted by the
> hardware.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message
      commit: a5bf5272295d3f058adeee025d2a0b6625f8ba7b
[2/2] spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted
      commit: 10c24e0d2f7cd2bc8a847cf750f01301ce67dbc8

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

end of thread, other threads:[~2025-06-09 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 13:37 [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Félix Piédallu via B4 Relay
2025-06-06 13:37 ` [PATCH 1/2] spi: omap2-mcspi: Disable multi mode when CS should be kept asserted after message Félix Piédallu via B4 Relay
2025-06-06 13:37 ` [PATCH 2/2] spi: omap2-mcspi: Disable multi-mode when the previous message kept CS asserted Félix Piédallu via B4 Relay
2025-06-09 19:33 ` [PATCH 0/2] SPI: omap2-mcspi: Fix SPI CS behaviour around cs_change in SPI transfers Mark Brown

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