History

spi: support inter-word delay requirement for devices

Some devices are slow and cannot keep up with the SPI bus and therefore require a short delay between words of the SPI transfer. The example of this that I'm looking at is a SAMA5D2 with a minimum SPI clock of 400kHz talking to an AVR-based SPI slave. The AVR cannot put bytes on the bus fast enough to keep up with the SoC's SPI controller even at the lowest bus speed. This patch introduces the ability to specify a required inter-word delay for SPI devices. It is up to the controller driver to configure itself accordingly in order to introduce the requested delay. Note that, for spi_transfer, there is already a field word_delay that provides similar functionality. This field, however, is specified in clock cycles (and worse, SPI controller cycles, not SCK cycles); that makes this value dependent on the master clock instead of the device clock for which the delay is intended to provide some relief. This patch leaves this old word_delay in place and provides a time-based word_delay_us alongside it; the new field fits in the struct padding so struct size is constant. There is only one in-kernel user of the word_delay field and presumably that driver could be reworked to use the time-based value instead. The time-based delay is limited to 8 bits as these delays are intended to be short. The SAMA5D2 that I've tested this on limits delays to a maximum of ~100us, which is already many word-transfer periods even at the minimum transfer speed supported by the controller.

Jonas Bonn committed 7 years ago

Commit b7bb3671 parent f3fdea32 files · +11 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/spi/spi.h+6−0
@@ -122,6 +122,8 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, · 121 unmodified lines
122122 * the spi_master.
123123 * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when
124124 * not using a GPIO line)
125+ * @word_delay_usecs: microsecond delay to be inserted between consecutive
126+ * words of a transfer
125127 *
126128 * @statistics: statistics for the spi_device
127129 *
@@ -169,6 +171,7 @@ struct spi_device { · 41 unmodified lines
169171 const char *driver_override;
170172 int cs_gpio; /* LEGACY: chip select gpio */
171173 struct gpio_desc *cs_gpiod; /* chip select gpio desc */
174+ uint8_t word_delay_usecs; /* inter-word delay */
172175
173176 /* the statistics */
174177 struct spi_statistics statistics;
@@ -721,6 +724,8 @@ extern void spi_res_release(struct spi_controller *ctlr, · 546 unmodified lines
721724 * @delay_usecs: microseconds to delay after this transfer before
722725 * (optionally) changing the chipselect status, then starting
723726 * the next transfer or completing this @spi_message.
727+ * @word_delay_usecs: microseconds to inter word delay after each word size
728+ * (set by bits_per_word) transmission.
724729 * @word_delay: clock cycles to inter word delay after each word size
725730 * (set by bits_per_word) transmission.
726731 * @transfer_list: transfers are sequenced through @spi_message.transfers
@@ -803,6 +808,7 @@ struct spi_transfer { · 76 unmodified lines
803808 #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
804809 #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
805810 u8 bits_per_word;
811+ u8 word_delay_usecs;
806812 u16 delay_usecs;
807813 u32 speed_hz;
808814 u16 word_delay;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t