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