[PATCH 3/3] spi: add ACPI support for SPI controller chip select lines(cs-gpios)

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

 



This will also allow to use cs-gpios for chip select in ACPI code
with no modification in the driver binding, like it be used in DT.
We could share almost all of the code with the DT path.

Signed-off-by: Jay Fang <f.fangjian@xxxxxxxxxx>
---
 drivers/spi/spi.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6ca5940..81d404a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2075,16 +2075,13 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(__spi_alloc_controller);
 
-#ifdef CONFIG_OF
-static int of_spi_register_master(struct spi_controller *ctlr)
+static int __spi_register_controller(struct spi_controller *ctlr)
 {
 	int nb, i, *cs;
 	struct device_node *np = ctlr->dev.of_node;
+	struct gpio_desc *desc;
 
-	if (!np)
-		return 0;
-
-	nb = of_gpio_named_count(np, "cs-gpios");
+	nb = gpiod_count(&ctlr->dev, "cs");
 	ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect);
 
 	/* Return error only for an incorrectly formed cs-gpios property */
@@ -2103,17 +2100,20 @@ static int of_spi_register_master(struct spi_controller *ctlr)
 	for (i = 0; i < ctlr->num_chipselect; i++)
 		cs[i] = -ENOENT;
 
-	for (i = 0; i < nb; i++)
-		cs[i] = of_get_named_gpio(np, "cs-gpios", i);
-
-	return 0;
-}
-#else
-static int of_spi_register_master(struct spi_controller *ctlr)
-{
+	if (IS_ENABLED(CONFIG_OF) && np) {
+		for (i = 0; i < nb; i++)
+			cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+	} else if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(&ctlr->dev)) {
+		for (i = 0; i < nb; i++) {
+			desc = devm_gpiod_get_index(&ctlr->dev, "cs",
+						    i, GPIOD_ASIS);
+			if (IS_ERR(desc))
+				continue;
+			cs[i] = desc_to_gpio(desc);
+		}
+	}
 	return 0;
 }
-#endif
 
 static int spi_controller_check_ops(struct spi_controller *ctlr)
 {
@@ -2177,7 +2177,7 @@ int spi_register_controller(struct spi_controller *ctlr)
 		return status;
 
 	if (!spi_controller_is_slave(ctlr)) {
-		status = of_spi_register_master(ctlr);
+		status = __spi_register_controller(ctlr);
 		if (status)
 			return status;
 	}
-- 
2.7.4




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux