mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-10 15:54:39 +08:00
spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE
[ Upstream commit7dbfa445ff
] Commitf3186dd876
("spi: Optionally use GPIO descriptors for CS GPIOs") has changed the user-space interface so that bogus SPI_CS_HIGH started to appear in the mask returned by SPI_IOC_RD_MODE even for active-low CS pins. Commit138c9c32f0
("spi: spidev: Fix CS polarity if GPIO descriptors are used") fixed only SPI_IOC_WR_MODE part of the problem. Let's fix SPI_IOC_RD_MODE symmetrically. Test case: #include <sys/ioctl.h> #include <fcntl.h> #include <linux/spi/spidev.h> int main(int argc, char **argv) { char modew = SPI_CPHA; char moder; int f = open("/dev/spidev0.0", O_RDWR); if (f < 0) return 1; ioctl(f, SPI_IOC_WR_MODE, &modew); ioctl(f, SPI_IOC_RD_MODE, &moder); return moder == modew ? 0 : 2; } Fixes:f3186dd876
("spi: Optionally use GPIO descriptors for CS GPIOs") Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com> Link: https://lore.kernel.org/r/20221130162927.539512-1-alexander.sverdlin@siemens.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
b6d27d9250
commit
f58888434d
@ -376,11 +376,22 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
/* read requests */
|
/* read requests */
|
||||||
case SPI_IOC_RD_MODE:
|
case SPI_IOC_RD_MODE:
|
||||||
retval = put_user(spi->mode & SPI_MODE_MASK,
|
|
||||||
(__u8 __user *)arg);
|
|
||||||
break;
|
|
||||||
case SPI_IOC_RD_MODE32:
|
case SPI_IOC_RD_MODE32:
|
||||||
retval = put_user(spi->mode & SPI_MODE_MASK,
|
tmp = spi->mode;
|
||||||
|
|
||||||
|
{
|
||||||
|
struct spi_controller *ctlr = spi->controller;
|
||||||
|
|
||||||
|
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
|
||||||
|
ctlr->cs_gpiods[spi->chip_select])
|
||||||
|
tmp &= ~SPI_CS_HIGH;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd == SPI_IOC_RD_MODE)
|
||||||
|
retval = put_user(tmp & SPI_MODE_MASK,
|
||||||
|
(__u8 __user *)arg);
|
||||||
|
else
|
||||||
|
retval = put_user(tmp & SPI_MODE_MASK,
|
||||||
(__u32 __user *)arg);
|
(__u32 __user *)arg);
|
||||||
break;
|
break;
|
||||||
case SPI_IOC_RD_LSB_FIRST:
|
case SPI_IOC_RD_LSB_FIRST:
|
||||||
|
Loading…
Reference in New Issue
Block a user