1b7952ab18ca54ee5e9ec4fbeed8d80ef634a8db
[openwrt/staging/pepe2k.git] /
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 <=
5 1 Mbps
6
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.
10
11 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
12 ---
13 drivers/spi/spi-gpio.c | 18 ++++++++++++------
14 1 file changed, 12 insertions(+), 6 deletions(-)
15
16 --- a/drivers/spi/spi-gpio.c
17 +++ b/drivers/spi/spi-gpio.c
18 @@ -11,12 +11,12 @@
19 #include <linux/gpio/consumer.h>
20 #include <linux/of.h>
21 #include <linux/of_device.h>
22 +#include <linux/delay.h>
23
24 #include <linux/spi/spi.h>
25 #include <linux/spi/spi_bitbang.h>
26 #include <linux/spi/spi_gpio.h>
27
28 -
29 /*
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
33 }
34
35 /*
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.
45 */
46 -#define spidelay(nsecs) do {} while (0)
47 +
48 +static inline void spidelay(unsigned long nsecs)
49 +{
50 + if (nsecs >= 500)
51 + ndelay(nsecs);
52 +}
53
54 #include "spi-bitbang-txrx.h"
55