Skip to content

Commit

Permalink
spi: fsl-spi: Fix CPM/QE mode Litte Endian
Browse files Browse the repository at this point in the history
CPM has the same problem as QE so for CPM also use the fix added
by commit 0398fb7 ("spi/spi_mpc8xxx: Fix QE mode Litte Endian"):

  CPM mode uses Little Endian so words > 8 bits are byte swapped.
  Workaround this by always enforcing wordsize 8 for 16 and 32 bits
  words. Unfortunately this will not work for LSB transfers
  where wordsize is > 8 bits so disable these for now.

Also limit the workaround to 16 and 32 bits words because it can
only work for multiples of 8-bits.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Fixes: 0398fb7 ("spi/spi_mpc8xxx: Fix QE mode Litte Endian")
Link: https://lore.kernel.org/r/1b7d3e84b1128f42c1887dd2fb9cdf390f541bc1.1680371809.git.christophe.leroy@csgroup.eu
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Christophe Leroy authored and Mark Brown committed Apr 5, 2023
1 parent 43bac51 commit c20c57d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/spi/spi-fsl-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,20 @@ static int mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs,
struct spi_device *spi,
int bits_per_word)
{
/* QE uses Little Endian for words > 8
* so transform all words > 8 into 8 bits
/* CPM/QE uses Little Endian for words > 8
* so transform 16 and 32 bits words into 8 bits
* Unfortnatly that doesn't work for LSB so
* reject these for now */
/* Note: 32 bits word, LSB works iff
* tfcr/rfcr is set to CPMFCR_GBL */
if (spi->mode & SPI_LSB_FIRST &&
bits_per_word > 8)
return -EINVAL;
if (bits_per_word > 8)
if (bits_per_word <= 8)
return bits_per_word;
if (bits_per_word == 16 || bits_per_word == 32)
return 8; /* pretend its 8 bits */
return bits_per_word;
return -EINVAL;
}

static int fsl_spi_setup_transfer(struct spi_device *spi,
Expand Down Expand Up @@ -222,7 +224,7 @@ static int fsl_spi_setup_transfer(struct spi_device *spi,
bits_per_word = mspi_apply_cpu_mode_quirks(cs, spi,
mpc8xxx_spi,
bits_per_word);
else if (mpc8xxx_spi->flags & SPI_QE)
else
bits_per_word = mspi_apply_qe_mode_quirks(cs, spi,
bits_per_word);

Expand Down

0 comments on commit c20c57d

Please sign in to comment.