Private
Public Access
2
0

spi.c: Stop trusting SPI_IOC_RD_MAX_SPEED_HZ from the kernel and trust our users

SPI_IOC_RD_MAX_SPEED_HZ is often incorrect and too low (RPI, UP2, galileo g1 at
least). Likely this is because driver writers are too concious of possible
issues or because they don't have the final hardware. Because of this we now
will only LOG_NOTICE on exceeding SPI_IOC_RD_MAX_SPEED_HZ and try keep going
anyways. This effectively will put the burden of not exceeding
SPI_IOC_RD_MAX_SPEED_HZ on our users.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2018-01-19 09:58:57 +01:00
parent ae2371c804
commit 7840710d1b

View File

@@ -256,9 +256,12 @@ mraa_spi_frequency(mraa_spi_context dev, int hz)
int speed = 0;
dev->clock = hz;
if (ioctl(dev->devfd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) != -1) {
if (speed < hz) {
dev->clock = speed;
syslog(LOG_WARNING, "spi: Selected speed reduced to max allowed speed");
if (speed < hz) {
// We wanted to never go higher than SPI_IOC_RD_MAX_SPEED_HZ but it
// seems a bunch of drivers don't have this set to the actual max
// so we only complain about it
// dev->clock = speed;
syslog(LOG_NOTICE, "spi: Selected speed (%dhz) is higher than the kernel max allowed speed (%shz)", hz, SPI_IOC_RD_MAX_SPEED_HZ);
}
}
return MRAA_SUCCESS;