Verdin iMX8M-Plus: spidev doesn't accept SPI_LSB_FIRST flag

Hello,

I’m testing spi parameters on a Dahlia board with iMX8M-Plus on it. I enabled spidev1.0 in device tree and put a jumper on MISO and MOSI pins on X20 header.

I’m on a nightly build of BSP5 and using preempt patch.
Linux localhost 5.4.161-rt67-0+git.75d336c1651a #1 SMP PREEMPT_RT Tue Feb 15 12:08:00 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

Following command works fine.

spidev_test --verbose --device /dev/spidev1.0 --speed 40000000
spi mode: 0x0
bits per word: 8
max speed: 40000000 Hz (40000 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  |......@.........................|
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  |......@.........................|

But as soon as I add --lsb flag (least significant bit first), it fails:

spidev_test --verbose --device /dev/spidev1.0 --speed 40000000 --lsb
can't set spi mode: Invalid argument
Aborted

I have tested it also with spidev driver in my C code. As soon as I add SPI_LSB_FIRST flag into mode parameter, it fails with the same error message.

Thank you.

Hi @Fide !

I could reproduce the issue here with:

  • Verdin iMX8M Plus Q 4GB WB IT V1.0B;
  • running Reference Multimedia 5.4.0-devel-20220127151830+build.0
  • non-RT distro

This really seems to be a driver-related issue. I rebuilt the spi and the spidev to allow them to debug messages and this is what I got:

Without --lsb

root@verdin-imx8mp-06849036:/sys/kernel/debug# spidev_test --verbose --device /dev/spidev1.0 --speed 40000000
[ 9142.324212] spidev spi1.0: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 9142.330987] spidev spi1.0: spi mode 0
[ 9142.334763] spidev spi1.0: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 9142.341517] spidev spi1.0: 8 bits per word
[ 9142.345688] spidev spi1.0: setup mode 0, 8 bits/w, 40000000 Hz max --> 0
[ 9142.352447] spidev spi1.0: 40000000 Hz (max)
spi mode: 0x0
bits per word: 8
max speed: 40000000 Hz (40000 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  |......@.........................|
RX | FF FF FF FF FF FF A0 00 00 00 00 4A FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F8 06  |...........J....................

With --lsb

root@verdin-imx8mp-06849036:/sys/kernel/debug# spidev_test --verbose --device /dev/spidev1.0 --speed 40000000 --lsb
[ 9328.278064] spidev spi1.0: setup: unsupported mode bits 8
[ 9328.283909] audit: type=1701 audit(1645805431.946:12): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=1136 comm="spidev_test" exe="/usr/bin/spidev_test" sig=6 res=1
can't set spi mode: Invalid argument
Aborted

As far as I understand, this is strange since this 8-bit mode should be the same for both, as only the ordering changed.

I will try to find the error and get back to you later. If this is indeed related to the NXP driver, you probably will need to ask on their forum.

Best regards,

1 Like

HI @Fide!

Digging deeper into the SPI driver, nothing could be found related to the LSB mode. Indeed, among the allowed modes, the LSB even can’t be set on the driver.

Also, there is no mention of LSB mode for SPI interfaces on the i.MX8 M Plus Reference Manual from NXP.

So we have several indications that the SPI driver (and probably the hadware) doesn’t support this LSB mode.


For completeness: I misinterpreted the error message spidev spi1.0: setup: unsupported mode bits 8. Actually, this message means that the bit 0x8 (0b1000), that actually represents the LSB mode, is unsupported.

Best regards,

1 Like