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 <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8759
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek 2025-02-15 08:11:02 +01:00 committed by Antonio Borneo
parent 0d7d178ed4
commit f63b41bbe4
1 changed files with 13 additions and 1 deletions

View 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;