bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0696-spi-gpio-Add-sck-idle-input-property.patch
1 From c979072887ef70aab2ab6e71544853df71017925 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Wed, 12 Jan 2022 08:23:28 +0000
4 Subject: [PATCH] spi: gpio: Add sck-idle-input property
5
6 The sck-idle-input property indicates that the spi-gpio driver should
7 return the SCK line to an input when the chip select signals are
8 inactive.
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 ---
12 drivers/spi/spi-gpio.c | 13 +++++++++++--
13 1 file changed, 11 insertions(+), 2 deletions(-)
14
15 --- a/drivers/spi/spi-gpio.c
16 +++ b/drivers/spi/spi-gpio.c
17 @@ -35,6 +35,7 @@ struct spi_gpio {
18 struct gpio_desc *sck;
19 struct gpio_desc *miso;
20 struct gpio_desc *mosi;
21 + bool sck_idle_input;
22 struct gpio_desc **cs_gpios;
23 };
24
25 @@ -201,8 +202,12 @@ static void spi_gpio_chipselect(struct s
26 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
27
28 /* set initial clock line level */
29 - if (is_active)
30 - gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL);
31 + if (is_active) {
32 + if (spi_gpio->sck_idle_input)
33 + gpiod_direction_output(spi_gpio->sck, spi->mode & SPI_CPOL);
34 + else
35 + gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL);
36 + }
37
38 /* Drive chip select line, if we have one */
39 if (spi_gpio->cs_gpios) {
40 @@ -211,6 +216,9 @@ static void spi_gpio_chipselect(struct s
41 /* SPI chip selects are normally active-low */
42 gpiod_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active);
43 }
44 +
45 + if (spi_gpio->sck_idle_input && !is_active)
46 + gpiod_direction_input(spi_gpio->sck);
47 }
48
49 static int spi_gpio_setup(struct spi_device *spi)
50 @@ -289,6 +297,7 @@ static int spi_gpio_request(struct devic
51 if (IS_ERR(spi_gpio->miso))
52 return PTR_ERR(spi_gpio->miso);
53
54 + spi_gpio->sck_idle_input = device_property_read_bool(dev, "sck-idle-input");
55 spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW);
56 return PTR_ERR_OR_ZERO(spi_gpio->sck);
57 }