Skip to content

Commit d61ad23

Browse files
fancerbroonie
authored andcommitted
spi: Clear SPI_CS_HIGH flag from bad_bits for GPIO chip-select
When GPIO chip-select is used nothing prevents any available SPI controllers to work with both CS-high and traditional CS-low modes. In fact the SPI bus core code already does it, so we don't need to introduce any modification there. But spi_setup() still fails to switch the interface settings if CS-high flag is set for the case of GPIO-driven slave chip-select when the SPI controller doesn't support the hardwired CS-inversion. Lets fix it by clearing the SPI_CS_HIGH flag out from bad_bits (unsupported by controller) when client chip is selected by GPIO. This feature is useful for slave devices, which in accordance with communication protocol can work with both active-high and active-low chip-selects. I am aware of one such device. It is MMC-SPI interface, when at init sequence the driver needs to perform a read operation with low and high chip-select sequentially (requirement of 74 clock cycles with both chipselect, see the mmc_spi driver for details). Signed-off-by: Serge Semin <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 1dfbf33 commit d61ad23

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/spi/spi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,11 @@ int spi_setup(struct spi_device *spi)
29452945
* so it is ignored here.
29462946
*/
29472947
bad_bits = spi->mode & ~(spi->controller->mode_bits | SPI_CS_WORD);
2948+
/* nothing prevents from working with active-high CS in case if it
2949+
* is driven by GPIO.
2950+
*/
2951+
if (gpio_is_valid(spi->cs_gpio))
2952+
bad_bits &= ~SPI_CS_HIGH;
29482953
ugly_bits = bad_bits &
29492954
(SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL |
29502955
SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL);

0 commit comments

Comments
 (0)