archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <>
To: Lukas Wunner <lukas-JFq808J9C/>
Cc: Mark Brown <>,
	linux-spi <>,
	Simon Han <>
Subject: Re: [PATCH] spi: spidev: Fix CS polarity if GPIO descriptors are used
Date: Wed, 19 Feb 2020 16:47:50 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <fca3ba7cdc930cd36854666ceac4fbcf01b89028.1582027457.git.lukas-JFq808J9C/>

On Tue, Feb 18, 2020 at 1:08 PM Lukas Wunner <lukas-JFq808J9C/> 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 <lukas-JFq808J9C/>
> Cc: # 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?

Linus Walleij

  parent reply	other threads:[~2020-02-19 15:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 12:08 Lukas Wunner
     [not found] ` <fca3ba7cdc930cd36854666ceac4fbcf01b89028.1582027457.git.lukas-JFq808J9C/>
2020-02-19 15:47   ` Linus Walleij [this message]
     [not found]     ` <>
2020-02-20  6:11       ` Lukas Wunner
     [not found]         ` <20200220061122.srkb663imntm4c6a-JFq808J9C/>
2020-02-20  6:18           ` Lukas Wunner
2020-02-21 13:20           ` Linus Walleij
2020-02-21 14:21   ` Applied "spi: spidev: Fix CS polarity if GPIO descriptors are used" to the spi tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \
    --cc=lukas-JFq808J9C/ \ \
    --subject='Re: [PATCH] spi: spidev: Fix CS polarity if GPIO descriptors are used' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).