950-0901-spi-spi-gpio-Implement-spidelay-when-requested-bit-r.patch 1.9 KB

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