public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: "Robin Murphy" <robin.murphy@arm.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Christian Hewitt" <christianshewitt@gmail.com>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] spi: bitbang: Fix lsb-first Rx
Date: Wed, 3 Aug 2022 16:02:29 +0100	[thread overview]
Message-ID: <YuqOBYJSP8Pm7Bz5@sirena.org.uk> (raw)
In-Reply-To: <28324d8622da80461cce35a82859b003d6f6c4b0.1659538737.git.robin.murphy@arm.com>

[-- Attachment #1: Type: text/plain, Size: 2226 bytes --]

On Wed, Aug 03, 2022 at 03:58:57PM +0100, Robin Murphy wrote:
> Shifting the recieved bit by "bits" inserts it at the top of the
> *currently remaining* Tx data, so we end up accumulating the whole
> transfer into bit 0 of the output word. Oops.
> 
> For the algorithm to work as intended, we need to remember where the
> top of the *original* word was, and shift Rx to there.

So if this never worked we presumably have some systems out there which
somehow rely on the old behaviour that we need to fix somehow - copying
in everyone from the original change...

> Fixes: 1847e3046c52 ("spi: gpio: Implement LSB First bitbang support")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/spi/spi-bitbang-txrx.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-bitbang-txrx.h b/drivers/spi/spi-bitbang-txrx.h
> index 267342dfa738..2dcbe166df63 100644
> --- a/drivers/spi/spi-bitbang-txrx.h
> +++ b/drivers/spi/spi-bitbang-txrx.h
> @@ -116,6 +116,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi,
>  {
>  	/* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
>  
> +	u8 rxbit = bits - 1;
>  	u32 oldbit = !(word & 1);
>  	/* clock starts at inactive polarity */
>  	for (; likely(bits); bits--) {
> @@ -135,7 +136,7 @@ bitbang_txrx_le_cpha0(struct spi_device *spi,
>  		/* sample LSB (from slave) on leading edge */
>  		word >>= 1;
>  		if ((flags & SPI_MASTER_NO_RX) == 0)
> -			word |= getmiso(spi) << (bits - 1);
> +			word |= getmiso(spi) << rxbit;
>  		setsck(spi, cpol);
>  	}
>  	return word;
> @@ -148,6 +149,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi,
>  {
>  	/* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
>  
> +	u8 rxbit = bits - 1;
>  	u32 oldbit = !(word & 1);
>  	/* clock starts at inactive polarity */
>  	for (; likely(bits); bits--) {
> @@ -168,7 +170,7 @@ bitbang_txrx_le_cpha1(struct spi_device *spi,
>  		/* sample LSB (from slave) on trailing edge */
>  		word >>= 1;
>  		if ((flags & SPI_MASTER_NO_RX) == 0)
> -			word |= getmiso(spi) << (bits - 1);
> +			word |= getmiso(spi) << rxbit;
>  	}
>  	return word;
>  }
> -- 
> 2.36.1.dirty
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-08-03 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 14:58 [PATCH] spi: bitbang: Fix lsb-first Rx Robin Murphy
2022-08-03 15:02 ` Mark Brown [this message]
2022-08-03 15:22   ` Robin Murphy
2022-08-03 16:33     ` Mark Brown
2022-08-15 15:58 ` 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=YuqOBYJSP8Pm7Bz5@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=afaerber@suse.de \
    --cc=christianshewitt@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=robin.murphy@arm.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