linuxlinux-kernelarmspiioctl

The difference between SPI_IOC_RD_MODE and SPI_IOC_RD_MODE32?


My device uses ARM for processing, and the operating system is 32-bit. When I use SPI in the application layer, if the parameter in the ioctl() function is SPI_IOC_WR_MODE, no error will be reported. If it is SPI_IOC_WR_MODE32, the following error will be reported:

can't set spi mode: Inappropriate ioctl for device

What is the difference between these two options?

ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
    pabort("can't set spi mode");

Solution

  • These IOCTLs are kinda version "1" and version "2" of the same. During the time some more bits were required. Instead of adding some version field the new IOCTLs had been introduced.

    The older one, i.e. SPI_IOC_*_MODE are used when the mode field is only 8-bit wide, while SPI_IOC_*_MODE32 are expected to operate on 32-bit argument. You can see the list of possible bits and check for the 8 LSB ones that are supported by both IOCTLs. And the respective handling code is the same with only the difference in the argument size.

    The error you see means that in your case the device doesn't support it (old kernel?) or invalid size of the argument (but the latter according to the code should not even compile). So, without an additional information it is hard to tell what exactly is wrong in your case, but at least you should now know the difference between those IOCTLs.