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