From 7840710d1bd6a5b616412a667003892b94e866fc Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Fri, 19 Jan 2018 09:58:57 +0100 Subject: [PATCH] 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 --- src/spi/spi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/spi/spi.c b/src/spi/spi.c index 2a1c688..2d9486c 100644 --- a/src/spi/spi.c +++ b/src/spi/spi.c @@ -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;