]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
drivers/linuxspidev: fix compilation on Linux older than 3.15
authorTomas Vanek <vanekt@fbl.cz>
Sat, 15 Feb 2025 07:11:02 +0000 (08:11 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 22 Feb 2025 18:33:33 +0000 (18:33 +0000)
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 <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8759
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/jtag/drivers/linuxspidev.c

index 6a149a977ba75938465a3f689e1b0742f2ee2a09..18abdc7db36bdf5c9669b9575719ee8cac5ae2a8 100644 (file)
@@ -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;