1 From 586f87307e75552292cfc6c76b81cd38d5ec31e2 Mon Sep 17 00:00:00 2001
2 From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
3 Date: Mon, 4 Sep 2023 10:57:47 +0100
4 Subject: [PATCH] spi: spi-gpio: Implement spidelay when requested bit rate <=
7 Formerly the delay was omitted as bit-banged SPI seldom achieved
8 even one Mbit/s; but some modern platforms can run faster, and
9 some SPI devices may need to be clocked slower.
11 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
13 drivers/spi/spi-gpio.c | 18 ++++++++++++------
14 1 file changed, 12 insertions(+), 6 deletions(-)
16 --- a/drivers/spi/spi-gpio.c
17 +++ b/drivers/spi/spi-gpio.c
19 #include <linux/gpio/consumer.h>
21 #include <linux/of_device.h>
22 +#include <linux/delay.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/spi_bitbang.h>
26 #include <linux/spi/spi_gpio.h>
30 * This bitbanging SPI master driver should help make systems usable
31 * when a native hardware SPI engine is not available, perhaps because
32 @@ -111,12 +111,18 @@ static inline int getmiso(const struct s
36 - * NOTE: this clocks "as fast as we can". It "should" be a function of the
37 - * requested device clock. Software overhead means we usually have trouble
38 - * reaching even one Mbit/sec (except when we can inline bitops), so for now
39 - * we'll just assume we never need additional per-bit slowdowns.
40 + * Generic bit-banged GPIO SPI might free-run at something in the range
41 + * 1Mbps ~ 10Mbps (depending on the platform), and some SPI devices may
42 + * need to be clocked at a lower rate. ndelay() is often implemented by
43 + * udelay() with rounding up, so do the delay only for nsecs >= 500
44 + * (<= 1Mbps). The conditional test adds a small overhead.
46 -#define spidelay(nsecs) do {} while (0)
48 +static inline void spidelay(unsigned long nsecs)
54 #include "spi-bitbang-txrx.h"