Linux-SPI Archive mirror
 help / color / mirror / Atom feed
From: Louis Chauvet <louis.chauvet@bootlin.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	 miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com,
	 yen-mei.goh@keysight.com, jeremie.dautheribes@bootlin.com,
	 Louis Chauvet <louis.chauvet@bootlin.com>
Subject: [PATCH] spi: omap2-mcspi: Ensure that CS is correctly asserted when switching from MULTI mode to SINGLE mode
Date: Tue, 09 Apr 2024 19:25:33 +0200	[thread overview]
Message-ID: <20240409-fix-omap2-mcspi-v1-1-f2b881ae196d@bootlin.com> (raw)

The OMAP2 support features a "multi" mode, where the controller
automatically sets the Chip Select (CS) when necessary. This mode allows
for shorter delays between CS selection and word content, but the CS is
always deasserted at the end.

The default transfer_one_message function expects the last transfer of a
message to keep the CS enabled. However, when two consecutive messages
use "multi" mode followed by "single" mode, the chipselect is not enabled
during the second message. This discrepancy causes the driver to time
out.

To address this issue, the CS is now reasserted for each new message that
follows a "multi"-mode message. This change ensures proper CS handling
and prevents driver timeouts.

Fixes: d153ff4056cb ("spi: omap2-mcspi: Add support for MULTI-mode")

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 drivers/spi/spi-omap2-mcspi.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 7e3083b83534..571e4499f71c 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -1264,6 +1264,15 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr,
 	struct spi_transfer	*tr;
 	u8 bits_per_word;
 
+	/*
+	 * When the last transfer used multi-mode, the CS is not keep down by the controller.
+	 * The default transfer_one_message expect that the last transfer of a message keep the CS
+	 * active.
+	 * Ensure that the next call to spi_set_cs will work as expected if single-mode is used.
+	 */
+	if (mcspi->use_multi_mode)
+		master->last_cs = -1;
+
 	/*
 	 * The conditions are strict, it is mandatory to check each transfer of the list to see if
 	 * multi-mode is applicable.

---
base-commit: 51244b7df2f236cea87a10729d5cbc777d199e19
change-id: 20240408-fix-omap2-mcspi-a6b41142ad9a

Best regards,
-- 
Louis Chauvet <louis.chauvet@bootlin.com>


             reply	other threads:[~2024-04-09 17:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 17:25 Louis Chauvet [this message]
2024-04-09 17:48 ` [PATCH] spi: omap2-mcspi: Ensure that CS is correctly asserted when switching from MULTI mode to SINGLE mode Mark Brown

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=20240409-fix-omap2-mcspi-v1-1-f2b881ae196d@bootlin.com \
    --to=louis.chauvet@bootlin.com \
    --cc=broonie@kernel.org \
    --cc=jeremie.dautheribes@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yen-mei.goh@keysight.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).