spi: use_gpio_descriptor fixup moved to spi_setup
authorPhil Elwell <phil@raspberrypi.com>
Mon, 20 Apr 2020 12:30:49 +0000 (13:30 +0100)
committerpopcornmix <popcornmix@gmail.com>
Wed, 1 Jul 2020 15:33:50 +0000 (16:33 +0100)
commitaaf478dbeaa39645e61548a5d9ae75a819eada11
tree68032313fa903fd030e991c0dcf5565ccf091a8d
parent6ef92e60325c5a8b65aa02ab2b7929351b14faa4
spi: use_gpio_descriptor fixup moved to spi_setup

Commits [1] and [2] including code that forces SPI_CS_HIGH for SPI
controllers that use GPIO descriptors, the SPI_CS_HIGH flag being
there to avoid a double-negation (since SPI CS is usually active-low).
The motivation for pushing the knowledge of the required polarity into
the GPIO descriptor allows the switch to an output to request the
correct inactive level, avoiding a needless glitch.

The problem with setting the flag early as [1] does is that it appears
in the mode field that is passed to client drivers during their probing,
when they may want to choose SPI_POL, SPI_PHA and (just possibly)
SPI_CS_HIGH. Since SPI_CS_HIGH is the exception, most drivers won't
set it and the anti-negation negation is lost. [2] acknowledges that
problem and patches things up for the case of users of spidev, but
omits regular kernel-mode drivers.

Downstream commit [3] moves the forcing of SPI_CS_HIGH to spi_setup,
after the driver probing. Since this code is called before any CS
manipulation it is early enough to be effective, but late enough that
clients have already had their chance to change the mode field.

This is a partial reversion of [1], and is accompanied by a complete
reversion of [2], neither of which is needed any longer.

[1] f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
[2] 83b2a8fe43bd ("spi: spidev: Fix CS polarity if GPIO descriptors are used")
[3] <varies> ("spi: Force CS_HIGH if GPIO descriptors are used")

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
drivers/spi/spi.c