Skip to content

Commit 4b68cf2

Browse files
pelwellpopcornmix
authored andcommitted
spi: Force CS_HIGH if GPIO descriptors are used
Commit f3186dd ("spi: Optionally use GPIO descriptors for CS GPIOs") amended of_spi_parse_dt() to always set SPI_CS_HIGH for SPI slaves whose Chip Select is defined by a "cs-gpios" devicetree property. This change breaks drivers whose probe functions set the mode field of the spi_device because in doing so they clear the SPI_CS_HIGH flag. Fix by setting SPI_CS_HIGH in spi_setup (under the same conditions as in of_spi_parse_dt()). See also: 83b2a8f ("spi: spidev: Fix CS polarity if GPIO descriptors are used") Fixes: f3186dd ("spi: Optionally use GPIO descriptors for CS GPIOs") Signed-off-by: Phil Elwell <phil@raspberrypi.com> SQUASH: spi: Demote SPI_CS_HIGH warning to KERN_DEBUG This warning is unavoidable from a client's perspective and doesn't indicate anything wrong (just surprising). SQUASH with "spi: use_gpio_descriptor fixup moved to spi_setup" Signed-off-by: Phil Elwell <phil@raspberrypi.com>
1 parent fe2bb00 commit 4b68cf2

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎drivers/spi/spi.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,7 @@ static int __spi_validate_bits_per_word(struct spi_controller *ctlr,
33543354
*/
33553355
int spi_setup(struct spi_device *spi)
33563356
{
3357+
struct spi_controller *ctlr = spi->controller;
33573358
unsigned bad_bits, ugly_bits;
33583359
int status;
33593360

@@ -3375,6 +3376,14 @@ int spi_setup(struct spi_device *spi)
33753376
(SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL |
33763377
SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
33773378
return -EINVAL;
3379+
3380+
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
3381+
ctlr->cs_gpiods[spi->chip_select] && !(spi->mode & SPI_CS_HIGH)) {
3382+
dev_dbg(&spi->dev,
3383+
"setup: forcing CS_HIGH (use_gpio_descriptors)\n");
3384+
spi->mode |= SPI_CS_HIGH;
3385+
}
3386+
33783387
/* help drivers fail *cleanly* when they need options
33793388
* that aren't supported with their current controller
33803389
* SPI_CS_WORD has a fallback software implementation,

0 commit comments

Comments
 (0)