History

spi: Add generic support for unused native cs with cs-gpios

Some SPI master controllers always drive a native chip select when performing a transfer. Hence when using both native and GPIO chip selects, at least one native chip select must be left unused, to be driven when performing transfers with slave devices using GPIO chip selects. Currently, to find an unused native chip select, SPI controller drivers need to parse and process cs-gpios theirselves. This is not only duplicated in each driver that needs it, but also duplicates part of the work done later at SPI controller registration time. Note that this cannot be done after spi_register_controller() returns, as at that time, slave devices may have been probed already. Hence add generic support to the SPI subsystem for finding an unused native chip select. Optionally, this unused native chip select, and all other in-use native chip selects, can be validated against the maximum number of native chip selects available on the controller hardware.

Geert Uytterhoeven committed 6 years ago

Commit 7d93aec1 parent e9aa3b82 files · +25 −0Browse files

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

Unified · Split

include/linux/spi/spi.h+8−0
@@ -423,6 +423,12 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 422 unmodified lines
423423 * GPIO descriptors rather than using global GPIO numbers grabbed by the
424424 * driver. This will fill in @cs_gpiods and @cs_gpios should not be used,
425425 * and SPI devices will have the cs_gpiod assigned rather than cs_gpio.
426+ * @unused_native_cs: When cs_gpiods is used, spi_register_controller() will
427+ * fill in this field with the first unused native CS, to be used by SPI
428+ * controller drivers that need to drive a native CS when using GPIO CS.
429+ * @max_native_cs: When cs_gpiods is used, and this field is filled in,
430+ * spi_register_controller() will validate all native CS (including the
431+ * unused native CS) against this value.
426432 * @statistics: statistics for the spi_controller
427433 * @dma_tx: DMA transmit channel
428434 * @dma_rx: DMA receive channel
@@ -624,6 +630,8 @@ struct spi_controller { · 195 unmodified lines
624630 int *cs_gpios;
625631 struct gpio_desc **cs_gpiods;
626632 bool use_gpio_descriptors;
633+ u8 unused_native_cs;
634+ u8 max_native_cs;
627635
628636 /* statistics */
629637 struct spi_statistics statistics;

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