[PATCH v2 1/2] spi: atmel_spi: Fix GPIO-based chip select handling to support multiple valid entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Current implementation of GPIO-based chip select configuration in this
driver only considers the first valid GPIO and ignores
subsequent entries. This patch ensures that all valid GPIO entries are
processed correctly, enabling configurations with multiple valid and
invalid entries.

Specifically, this change addresses the issue where configurations like
`cs-gpios = <&pioC 25 0>, <0>, <0>, <&pioC 28 0>;` are not handled
correctly, leading to the last valid GPIO being ignored.

Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---
 drivers/spi/atmel_spi.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 90f655dc3e..4adad241b4 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -414,11 +414,7 @@ static int atmel_spi_probe(struct device *dev)
 		for (i = 0; i < master->num_chipselect; i++) {
 			as->cs_pins[i] = of_get_named_gpio(node, "cs-gpios", i);
 
-			if (!gpio_is_valid(as->cs_pins[i]))
-			    break;
 		}
-
-		master->num_chipselect = i;
 	}
 
 	as->clk = clk_get(dev, "spi_clk");
@@ -438,9 +434,10 @@ static int atmel_spi_probe(struct device *dev)
 	atmel_get_caps(as);
 
 	for (i = 0; i < master->num_chipselect; i++) {
-		ret = gpio_request(as->cs_pins[i], dev_name(dev));
-		if (ret)
-			goto out_gpio;
+		if (gpio_is_valid(as->cs_pins[i]))
+			ret = gpio_request(as->cs_pins[i], dev_name(dev));
+			if (ret)
+				goto out_gpio;
 	}
 
 	/* Initialize the hardware */
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux