Skip to content

Commit 83b2a8f

Browse files
l1kgregkh
authored andcommitted
spi: spidev: Fix CS polarity if GPIO descriptors are used
commit 138c9c3 upstream. 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 broke userspace applications which issue an SPI_IOC_WR_MODE ioctl() to an spidev: Chip Select polarity will be incorrect unless the application is changed to set SPI_CS_HIGH. And once changed, it will be incompatible with kernels not containing the commit. Fix by setting SPI_CS_HIGH in spidev_ioctl() (under the same conditions as in of_spi_parse_dt()). Fixes: f3186dd ("spi: Optionally use GPIO descriptors for CS GPIOs") Reported-by: Simon Han <[email protected]> Signed-off-by: Lukas Wunner <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/fca3ba7cdc930cd36854666ceac4fbcf01b89028.1582027457.git.lukas@wunner.de Signed-off-by: Mark Brown <[email protected]> Cc: [email protected] # v5.1+ Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fc73ded commit 83b2a8f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/spi/spidev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,18 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
394394
else
395395
retval = get_user(tmp, (u32 __user *)arg);
396396
if (retval == 0) {
397+
struct spi_controller *ctlr = spi->controller;
397398
u32 save = spi->mode;
398399

399400
if (tmp & ~SPI_MODE_MASK) {
400401
retval = -EINVAL;
401402
break;
402403
}
403404

405+
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
406+
ctlr->cs_gpiods[spi->chip_select])
407+
tmp |= SPI_CS_HIGH;
408+
404409
tmp |= spi->mode & ~SPI_MODE_MASK;
405410
spi->mode = (u16)tmp;
406411
retval = spi_setup(spi);

0 commit comments

Comments
 (0)