From: Nick Hollinghurst Date: Mon, 4 Sep 2023 09:57:47 +0000 (+0100) Subject: spi: spi-gpio: Implement spidelay when requested bit rate <= 1 Mbps X-Git-Tag: accepted/tizen/unified/20240422.153132~426 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b92ae61aafd40c9da9593ef5f437690a60ad245f;p=platform%2Fkernel%2Flinux-rpi.git spi: spi-gpio: Implement spidelay when requested bit rate <= 1 Mbps Formerly the delay was omitted as bit-banged SPI seldom achieved even one Mbit/s; but some modern platforms can run faster, and some SPI devices may need to be clocked slower. Signed-off-by: Nick Hollinghurst --- diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 302e640..c95e4e9 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -10,12 +10,12 @@ #include #include #include +#include #include #include #include - /* * This bitbanging SPI host driver should help make systems usable * when a native hardware SPI engine is not available, perhaps because @@ -110,12 +110,18 @@ static inline int getmiso(const struct spi_device *spi) } /* - * NOTE: this clocks "as fast as we can". It "should" be a function of the - * requested device clock. Software overhead means we usually have trouble - * reaching even one Mbit/sec (except when we can inline bitops), so for now - * we'll just assume we never need additional per-bit slowdowns. + * Generic bit-banged GPIO SPI might free-run at something in the range + * 1Mbps ~ 10Mbps (depending on the platform), and some SPI devices may + * need to be clocked at a lower rate. ndelay() is often implemented by + * udelay() with rounding up, so do the delay only for nsecs >= 500 + * (<= 1Mbps). The conditional test adds a small overhead. */ -#define spidelay(nsecs) do {} while (0) + +static inline void spidelay(unsigned long nsecs) +{ + if (nsecs >= 500) + ndelay(nsecs); +} #include "spi-bitbang-txrx.h"