This is an automated email from Gerrit.

"Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which 
you can find at https://review.openocd.org/c/openocd/+/8759

-- gerrit

commit f571c3fce4917aa15daebe9edf55fa80d3cb242a
Author: Tomas Vanek <van...@fbl.cz>
Date:   Sat Feb 15 08:11:02 2025 +0100

    drivers/linuxspidev: fix compilation on Linux older than 3.15
    
    Although the commit [1] which introduced SPI_IOC_WR_MODE32 is 10 years
    old, some hardware may enforce old Linux because the vendor
    didn't bother with system updates.
    
    Change-Id: I76d0b38c8646b1be329418860916b9f01b90990d
    Link: [1] 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/include/uapi/linux/spi/spidev.h?h=linux-3.15.y&id=dc64d39b54c1e9db97a6fb1ca52598c981728157
    Signed-off-by: Tomas Vanek <van...@fbl.cz>

diff --git a/src/jtag/drivers/linuxspidev.c b/src/jtag/drivers/linuxspidev.c
index 6a149a977b..18abdc7db3 100644
--- a/src/jtag/drivers/linuxspidev.c
+++ b/src/jtag/drivers/linuxspidev.c
@@ -302,8 +302,20 @@ static int spidev_init(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
+       int ret;
        // Set SPI mode.
-       int ret = ioctl(spi_fd, SPI_IOC_WR_MODE32, &spi_mode);
+#ifdef SPI_IOC_WR_MODE32
+       ret = ioctl(spi_fd, SPI_IOC_WR_MODE32, &spi_mode);
+#else
+       // Linux pre 3.15 does not support MODE32, use 8-bit ioctl
+       if (spi_mode & ~0xff) {
+               LOG_ERROR("SPI mode 0x%" PRIx32 ", system permits 8 bits only", 
spi_mode);
+               return ERROR_JTAG_INIT_FAILED;
+       }
+
+       uint8_t mode = (uint8_t)spi_mode;
+       ret = ioctl(spi_fd, SPI_IOC_WR_MODE, &mode);
+#endif
        if (ret == -1) {
                LOG_ERROR("Failed to set SPI mode 0x%" PRIx32, spi_mode);
                return ERROR_JTAG_INIT_FAILED;

-- 

Reply via email to