From c00f864bf4e9889ebafe9bcbfc6de92c298f6919 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Jirman?= <megi@xff.cz>
Date: Sun, 14 Nov 2021 01:14:25 +0100
Subject: [PATCH 313/463] usb: typec: fusb302: Add OF extcon support

It's possible to create a dependency cycle between fusb302 and
other drivers via extcon device, so we retrieve the device on
demand after probe and not during probe.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/usb/typec/tcpm/fusb302.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index a2244fdbb60a8..5288e0e04343d 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -518,6 +518,16 @@ static int tcpm_get_current_limit(struct tcpc_dev *dev)
 	int current_limit = 0;
 	unsigned long timeout;
 
+	/*
+	 * To avoid cycles in OF dependencies, we get extcon when necessary
+	 * outside of probe function.
+	 */
+	if (of_property_read_bool(chip->dev->of_node, "extcon") && !chip->extcon) {
+		chip->extcon = extcon_get_edev_by_phandle(chip->dev, 0);
+		if (IS_ERR(chip->extcon))
+			chip->extcon = NULL;
+	}
+
 	if (!chip->extcon)
 		return 0;
 
-- 
2.46.0

