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

Message ID 1534859756-6955-2-git-send-email-loic.poulain@linaro.org
State Superseded
Headers show
Series
  • Untitled series #14116
Related show

Commit Message

Loic Poulain Aug. 21, 2018, 1:55 p.m.
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 <loic.poulain@linaro.org>

---
 drivers/usb/chipidea/core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

-- 
2.7.4

Patch

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;