[RESEND PATCH v2 0/2] spi: dtb parsing fixes

Changes from v1: * patches description was updated
Michael Polyntsov (1): spi: soft_spi: Parse cs-gpios only if num-chipselects is not <0>
Mikhail Kshevetskiy (1): spi: soft_spi: fix miso gpio property name
doc/device-tree-bindings/spi/soft-spi.txt | 5 +++-- drivers/spi/soft_spi.c | 24 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-)

The patch fix a missprint introduced in commit 2e9fe73a883a ("spi: soft_spi: Support the recommended soft spi properties").
Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@iopsys.eu Reviewed-by: Fabio Estevam festevam@gmail.com --- drivers/spi/soft_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 9bdb4a5bff9..04691d3a3ba 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -271,7 +271,7 @@ static int soft_spi_probe(struct udevice *dev) ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, GPIOD_IS_IN); if (ret) - ret = gpio_request_by_name(dev, "gpio-miso", 0, &plat->miso, + ret = gpio_request_by_name(dev, "miso-gpios", 0, &plat->miso, GPIOD_IS_IN); if (ret) plat->flags |= SPI_MASTER_NO_RX;

From: Michael Polyntsov michael.polyntsov@iopsys.eu
Some boards don't have chipselect lines for leds so cs-gpios is not specified in the dts leading to probing error. Fix it by making behavior similar to the one in Linux, parse num-chipselects and if it is zero, ignore cs-gpios.
Signed-off-by: Michael Polyntsov michael.polyntsov@iopsys.eu Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@iopsys.eu --- doc/device-tree-bindings/spi/soft-spi.txt | 5 +++-- drivers/spi/soft_spi.c | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/doc/device-tree-bindings/spi/soft-spi.txt b/doc/device-tree-bindings/spi/soft-spi.txt index bdf7e86befb..77b01b2fd9a 100644 --- a/doc/device-tree-bindings/spi/soft-spi.txt +++ b/doc/device-tree-bindings/spi/soft-spi.txt @@ -8,14 +8,15 @@ The soft SPI node requires the following properties:
Mandatory properties: compatible: "spi-gpio" -cs-gpios: GPIOs to use for SPI chip select (output) +cs-gpios: GPIOs to use for SPI chip select (output), not required if num-chipselects = <0> sck-gpios: GPIO to use for SPI clock (output) And at least one of: mosi-gpios: GPIO to use for SPI MOSI line (output) miso-gpios: GPIO to use for SPI MISO line (input)
-Optional propertie: +Optional properties: spi-delay-us: Number of microseconds of delay between each CS transition +num-chipselects: Number of chipselect lines
The GPIOs should be specified as required by the GPIO controller referenced. The first cell holds the phandle of the controller and the second cell diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index 04691d3a3ba..a8ec2f4f7b4 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -237,6 +237,18 @@ static int soft_spi_of_to_plat(struct udevice *dev) return 0; }
+static int retrieve_num_chipselects(struct udevice *dev) +{ + int chipselects; + int ret; + + ret = ofnode_read_u32(dev_ofnode(dev), "num-chipselects", &chipselects); + if (ret) + return ret; + + return chipselects; +} + static int soft_spi_probe(struct udevice *dev) { struct spi_slave *slave = dev_get_parent_priv(dev); @@ -249,7 +261,15 @@ static int soft_spi_probe(struct udevice *dev)
ret = gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs, GPIOD_IS_OUT | cs_flags); - if (ret) + /* + * If num-chipselects is zero we're ignoring absence of cs-gpios. This + * code relies on the fact that `gpio_request_by_name` call above + * initiailizes plat->cs to correct value with invalid GPIO even when + * there is no cs-gpios node in dts. All other functions which work + * with plat->cs verify it via `dm_gpio_is_valid` before using it, so + * such value doesn't cause any problems. + */ + if (ret && retrieve_num_chipselects(dev) != 0) return -EINVAL;
ret = gpio_request_by_name(dev, "gpio-sck", 0, &plat->sclk,

On Wed, 14 Aug 2024 at 04:14, Mikhail Kshevetskiy mikhail.kshevetskiy@iopsys.eu wrote:
From: Michael Polyntsov michael.polyntsov@iopsys.eu
Some boards don't have chipselect lines for leds so cs-gpios is not specified in the dts leading to probing error. Fix it by making behavior similar to the one in Linux, parse num-chipselects and if it is zero, ignore cs-gpios.
Signed-off-by: Michael Polyntsov michael.polyntsov@iopsys.eu Signed-off-by: Mikhail Kshevetskiy mikhail.kshevetskiy@iopsys.eu
doc/device-tree-bindings/spi/soft-spi.txt | 5 +++-- drivers/spi/soft_spi.c | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (2)
-
Mikhail Kshevetskiy
-
Simon Glass