[PATCH v3 2/7] NFC: trf7970a: Don't manage EN2 when not specified in DT

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

 




Currently, the trf7970a driver assumes that there is a GPIO
connected to the EN2 pin of the trf7970a part; however, that
may not always be the case.  Some boards may tie EN2 low and
not connect it to a GPIO.  Support these configurations by making
the driver ignore EN2 when the second entry in the 'ti,enable-gpios'
DT property is missing (i.e., the one that specifies the GPIO for
EN2).

Signed-off-by: Mark Greer <mgreer@xxxxxxxxxxxxxxx>
---
 drivers/nfc/trf7970a.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index 92f3cf3e012a..0c0567adefcb 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -1884,7 +1884,8 @@ static int trf7970a_power_up(struct trf7970a *trf)
 
 	usleep_range(5000, 6000);
 
-	if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) {
+	if (gpio_is_valid(trf->en2_gpio) &&
+	    !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) {
 		gpio_set_value(trf->en2_gpio, 1);
 		usleep_range(1000, 2000);
 	}
@@ -1915,7 +1916,8 @@ static int trf7970a_power_down(struct trf7970a *trf)
 
 	gpio_set_value(trf->en_gpio, 0);
 
-	if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW))
+	if (gpio_is_valid(trf->en2_gpio) &&
+	    !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW))
 		gpio_set_value(trf->en2_gpio, 0);
 
 	ret = regulator_disable(trf->regulator);
@@ -2018,7 +2020,7 @@ static int trf7970a_probe(struct spi_device *spi)
 	if (of_property_read_bool(np, "irq-status-read-quirk"))
 		trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ;
 
-	/* There are two enable pins - both must be present */
+	/* There are two enable pins - only EN must be present in DT */
 	trf->en_gpio = of_get_named_gpio(np, "ti,enable-gpios", 0);
 	if (!gpio_is_valid(trf->en_gpio)) {
 		dev_err(trf->dev, "No EN GPIO property\n");
@@ -2033,21 +2035,21 @@ static int trf7970a_probe(struct spi_device *spi)
 	}
 
 	trf->en2_gpio = of_get_named_gpio(np, "ti,enable-gpios", 1);
-	if (!gpio_is_valid(trf->en2_gpio)) {
-		dev_err(trf->dev, "No EN2 GPIO property\n");
-		return trf->en2_gpio;
-	}
+	if (gpio_is_valid(trf->en2_gpio)) {
+		ret = devm_gpio_request_one(trf->dev, trf->en2_gpio,
+					    GPIOF_DIR_OUT | GPIOF_INIT_LOW,
+					    "trf7970a EN2");
+		if (ret) {
+			dev_err(trf->dev, "Can't request EN2 GPIO: %d\n", ret);
+			return ret;
+		}
 
-	ret = devm_gpio_request_one(trf->dev, trf->en2_gpio,
-			GPIOF_DIR_OUT | GPIOF_INIT_LOW, "trf7970a EN2");
-	if (ret) {
-		dev_err(trf->dev, "Can't request EN2 GPIO: %d\n", ret);
-		return ret;
+		if (of_property_read_bool(np, "en2-rf-quirk"))
+			trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW;
+	} else {
+		dev_err(trf->dev, "No EN2 GPIO property - ignoring EN2\n");
 	}
 
-	if (of_property_read_bool(np, "en2-rf-quirk"))
-		trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW;
-
 	ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL,
 			trf7970a_irq, IRQF_TRIGGER_RISING | IRQF_ONESHOT,
 			"trf7970a", trf);
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux