From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Walleij Subject: Re: [PATCH] spi: spidev: Fix CS polarity if GPIO descriptors are used Date: Wed, 19 Feb 2020 16:47:50 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: Mark Brown , linux-spi , Simon Han To: Lukas Wunner Return-path: In-Reply-To: Sender: linux-spi-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: On Tue, Feb 18, 2020 at 1:08 PM Lukas Wunner wrote: > Commit f3186dd87669 ("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: f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs") > Reported-by: Simon Han > Signed-off-by: Lukas Wunner > Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org # v5.1+ > Cc: Linus Walleij (...) Nit: I would also insert a comment in the code to tell what is going on. > + if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && > + ctlr->cs_gpiods[spi->chip_select]) > + tmp |= SPI_CS_HIGH; Should this be tmp ^= SPI_CS_HIGH? If the device tree node for cs-gpios is actually active high, which happens, then you probably want the opposite of what was requested, right? Yours, Linus Walleij