bcm27xx: update patches from RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0674-spi-use_gpio_descriptor-fixup-moved-to-spi_setup.patch
1 From b4659f44df3454c6b37ba206a0347af3b8d6a744 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Mon, 20 Apr 2020 13:30:49 +0100
4 Subject: [PATCH] spi: use_gpio_descriptor fixup moved to spi_setup
5
6 Commits [1] and [2] including code that forces SPI_CS_HIGH for SPI
7 controllers that use GPIO descriptors, the SPI_CS_HIGH flag being
8 there to avoid a double-negation (since SPI CS is usually active-low).
9 The motivation for pushing the knowledge of the required polarity into
10 the GPIO descriptor allows the switch to an output to request the
11 correct inactive level, avoiding a needless glitch.
12
13 The problem with setting the flag early as [1] does is that it appears
14 in the mode field that is passed to client drivers during their probing,
15 when they may want to choose SPI_POL, SPI_PHA and (just possibly)
16 SPI_CS_HIGH. Since SPI_CS_HIGH is the exception, most drivers won't
17 set it and the anti-negation negation is lost. [2] acknowledges that
18 problem and patches things up for the case of users of spidev, but
19 omits regular kernel-mode drivers.
20
21 Downstream commit [3] moves the forcing of SPI_CS_HIGH to spi_setup,
22 after the driver probing. Since this code is called before any CS
23 manipulation it is early enough to be effective, but late enough that
24 clients have already had their chance to change the mode field.
25
26 This is a partial reversion of [1], and is accompanied by a complete
27 reversion of [2], neither of which is needed any longer.
28
29 [1] f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
30 [2] 83b2a8fe43bd ("spi: spidev: Fix CS polarity if GPIO descriptors are used")
31 [3] <varies> ("spi: Force CS_HIGH if GPIO descriptors are used")
32
33 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
34 ---
35 drivers/spi/spi.c | 9 ---------
36 1 file changed, 9 deletions(-)
37
38 --- a/drivers/spi/spi.c
39 +++ b/drivers/spi/spi.c
40 @@ -1775,15 +1775,6 @@ static int of_spi_parse_dt(struct spi_co
41 }
42 spi->chip_select = value;
43
44 - /*
45 - * For descriptors associated with the device, polarity inversion is
46 - * handled in the gpiolib, so all gpio chip selects are "active high"
47 - * in the logical sense, the gpiolib will invert the line if need be.
48 - */
49 - if ((ctlr->use_gpio_descriptors) && ctlr->cs_gpiods &&
50 - ctlr->cs_gpiods[spi->chip_select])
51 - spi->mode |= SPI_CS_HIGH;
52 -
53 /* Device speed */
54 rc = of_property_read_u32(nc, "spi-max-frequency", &value);
55 if (rc) {