diff options
| author | Michael Polyntsov <[email protected]> | 2024-07-31 08:11:29 +0400 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2024-08-15 11:28:47 -0600 |
| commit | 3d7f19459745262c54472e9c909b9e2f8daacea2 (patch) | |
| tree | bc54818b3a4ea9f75ee24a4bb15c75d2825d2b41 /drivers | |
| parent | 1d662a64a74115fa2897d07c3294b903afcafe6e (diff) | |
spi: soft_spi: Parse cs-gpios only if num-chipselects is not <0>
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 <[email protected]>
Signed-off-by: Mikhail Kshevetskiy <[email protected]>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/spi/soft_spi.c | 22 |
1 files changed, 21 insertions, 1 deletions
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, |
