[2/6] usb: chipidea: Support generic usb extcon

From: Loic Poulain <hidden>
Date: 2018-08-21 13:55:52
Subsystem: chipidea usb high speed dual role controller, the rest, usb subsystem · Maintainers: Peter Chen, Linus Torvalds, Greg Kroah-Hartman

Add compatibility for extcon-usb-gpio which can handle more
than one cable per instance, allowing coherency of USB cable
states (USB/USB-HOST). These states can be generated from ID
or/and VBUS pins.

In case only one extcon device is associated to the USB device,
and this device supports USB and USB-HOST cable states, we now
use it for both VBUS (USB) and ID (USB-HOST) notifier.

Signed-off-by: Loic Poulain <redacted>
---
 drivers/usb/chipidea/core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 03e52fc..c595718 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -699,6 +699,17 @@ static int ci_get_platdata(struct device *dev,
 		ext_id = extcon_get_edev_by_phandle(dev, 1);
 		if (IS_ERR(ext_id) && PTR_ERR(ext_id) != -ENODEV)
 			return PTR_ERR(ext_id);
+
+		/*
+		 * Some extcon devices like extcon-usb-gpio have only one
+		 * instance for both USB and USB-HOST cable states.
+		 */
+		if (!IS_ERR(ext_vbus) && IS_ERR(ext_id)) {
+			if (extcon_get_state(ext_vbus, EXTCON_USB) >= 0 &&
+			    extcon_get_state(ext_vbus, EXTCON_USB_HOST) >= 0) {
+				ext_id = ext_vbus;
+			}
+		}
 	}
 
 	cable = &platdata->vbus_extcon;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help