From 9a7e926353d5aea2d78ce507ae5bb3537cbccbed Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megous@megous.com>
Date: Tue, 12 Dec 2017 14:04:19 +0100
Subject: [PATCH 63/82] phy: sun4i-usb: Add DT property to force ID/VBUS
 polling

In some cases interrupts on GPIO don't fire for whatever reason.
Allow to force polling of ID/VBUS detection pins from DT.

Signed-off-by: Ondrej Jirman <megous@megous.com>
---
 drivers/phy/allwinner/phy-sun4i-usb.c | 44 ++++++++++++++-------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c
index 1f8809bab002..1cbb01c41d8d 100644
--- a/drivers/phy/allwinner/phy-sun4i-usb.c
+++ b/drivers/phy/allwinner/phy-sun4i-usb.c
@@ -816,29 +816,31 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
 		phy_set_drvdata(phy->phy, &data->phys[i]);
 	}
 
-	data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
-	if (data->id_det_irq > 0) {
-		ret = devm_request_irq(dev, data->id_det_irq,
-				sun4i_usb_phy0_id_vbus_det_irq,
-				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-				"usb0-id-det", data);
-		if (ret) {
-			dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
-			return ret;
+	if (!of_find_property(np, "force-poll-vbus-id-det", NULL)) {
+		data->id_det_irq = gpiod_to_irq(data->id_det_gpio);
+		if (data->id_det_irq > 0) {
+			ret = devm_request_irq(dev, data->id_det_irq,
+					sun4i_usb_phy0_id_vbus_det_irq,
+					IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+					"usb0-id-det", data);
+			if (ret) {
+				dev_err(dev, "Err requesting id-det-irq: %d\n", ret);
+				return ret;
+			}
 		}
-	}
 
-	data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
-	if (data->vbus_det_irq > 0) {
-		ret = devm_request_irq(dev, data->vbus_det_irq,
-				sun4i_usb_phy0_id_vbus_det_irq,
-				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-				"usb0-vbus-det", data);
-		if (ret) {
-			dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
-			data->vbus_det_irq = -1;
-			sun4i_usb_phy_remove(pdev); /* Stop detect work */
-			return ret;
+		data->vbus_det_irq = gpiod_to_irq(data->vbus_det_gpio);
+		if (data->vbus_det_irq > 0) {
+			ret = devm_request_irq(dev, data->vbus_det_irq,
+					sun4i_usb_phy0_id_vbus_det_irq,
+					IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+					"usb0-vbus-det", data);
+			if (ret) {
+				dev_err(dev, "Err requesting vbus-det-irq: %d\n", ret);
+				data->vbus_det_irq = -1;
+				sun4i_usb_phy_remove(pdev); /* Stop detect work */
+				return ret;
+			}
 		}
 	}
 
-- 
2.20.1

