The initial value of the device's mode_bits is set with an incorrect mask, because VIRTIO_SPI_CS_HIGH and VIRTIO_SPI_MODE_LSB_FIRST are not meant for the propagation of device capabilities but for transfers. This has the effect of: - setting SPI_CS_HIGH when the device advertises support for CPOL=0; - setting SPI_LSB_FIRST when the device advertises support for CPOL=1; - completely ignoring the CS_HIGH support advertised by the device. Use the correct VIRTIO_SPI_MF_ macros instead. While at it, use the correct macros also for the mode_bits assignments that follow, selecting the ones from the spi namespace (no functional change there, since their value is the same as the corresponding ones from the virtio namespace). Fixes: f98cabe3f6cf ("SPI: Add virtio SPI driver") Cc: stable@vger.kernel.org Signed-off-by: Francesco Valla --- drivers/spi/spi-virtio.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-virtio.c b/drivers/spi/spi-virtio.c index 2eeb79ff5aa2..66edc4dae02a 100644 --- a/drivers/spi/spi-virtio.c +++ b/drivers/spi/spi-virtio.c @@ -265,12 +265,13 @@ static void virtio_spi_read_config(struct virtio_device *vdev) mode_func_supported = virtio_cread32(vdev, offsetof(struct virtio_spi_config, mode_func_supported)); - ctrl->mode_bits = mode_func_supported & - (VIRTIO_SPI_CS_HIGH | VIRTIO_SPI_MODE_LSB_FIRST); + ctrl->mode_bits = 0; + if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CS_HIGH) + ctrl->mode_bits |= SPI_CS_HIGH; if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CPHA_1) - ctrl->mode_bits |= VIRTIO_SPI_CPHA; + ctrl->mode_bits |= SPI_CPHA; if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_CPOL_1) - ctrl->mode_bits |= VIRTIO_SPI_CPOL; + ctrl->mode_bits |= SPI_CPOL; if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_LSB_FIRST) ctrl->mode_bits |= SPI_LSB_FIRST; if (mode_func_supported & VIRTIO_SPI_MF_SUPPORT_LOOPBACK) --- base-commit: ca20d5a011d35fc25e328fe31ac47f7aae557c5a change-id: 20261129-spi-virtio-modebits-fix-10c734535167 Best regards, -- Francesco Valla