861-04_spi_gpio_implement_spi_delay.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Implement the SPI-GPIO delay function for busses that need speed limitation.
  2. --mb
  3. --- a/drivers/spi/spi-gpio.c
  4. +++ b/drivers/spi/spi-gpio.c
  5. @@ -22,6 +22,7 @@
  6. #include <linux/init.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/gpio.h>
  9. +#include <linux/delay.h>
  10. #include <linux/spi/spi.h>
  11. #include <linux/spi/spi_bitbang.h>
  12. @@ -70,6 +71,7 @@ struct spi_gpio {
  13. * #define SPI_MOSI_GPIO 120
  14. * #define SPI_SCK_GPIO 121
  15. * #define SPI_N_CHIPSEL 4
  16. + * #undef NEED_SPIDELAY
  17. * #include "spi-gpio.c"
  18. */
  19. @@ -77,6 +79,7 @@ struct spi_gpio {
  20. #define DRIVER_NAME "spi_gpio"
  21. #define GENERIC_BITBANG /* vs tight inlines */
  22. +#define NEED_SPIDELAY 1
  23. /* all functions referencing these symbols must define pdata */
  24. #define SPI_MISO_GPIO ((pdata)->miso)
  25. @@ -121,12 +124,20 @@ static inline int getmiso(const struct s
  26. #undef pdata
  27. /*
  28. - * NOTE: this clocks "as fast as we can". It "should" be a function of the
  29. - * requested device clock. Software overhead means we usually have trouble
  30. - * reaching even one Mbit/sec (except when we can inline bitops), so for now
  31. - * we'll just assume we never need additional per-bit slowdowns.
  32. + * NOTE: to clock "as fast as we can", set spi_device.max_speed_hz
  33. + * and spi_transfer.speed_hz to 0.
  34. + * Otherwise this is a function of the requested device clock.
  35. + * Software overhead means we usually have trouble
  36. + * reaching even one Mbit/sec (except when we can inline bitops). So on small
  37. + * embedded devices with fast SPI slaves you usually don't need a delay.
  38. */
  39. -#define spidelay(nsecs) do {} while (0)
  40. +static inline void spidelay(unsigned nsecs)
  41. +{
  42. +#ifdef NEED_SPIDELAY
  43. + if (unlikely(nsecs))
  44. + ndelay(nsecs);
  45. +#endif /* NEED_SPIDELAY */
  46. +}
  47. #include "spi-bitbang-txrx.h"