[RFC PATCH v2 2/4] usb: chipidea: otg: Do not rely on OTG with CI_HDRC_DUAL_ROLE_NOT_OTG

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

 



If CI_HDRC_DUAL_ROLE_NOT_OTG is specified do not use the OTGSC
registers.

Signed-off-by: Sanchayan Maity <maitysanchayan@xxxxxxxxx>
---
 drivers/usb/chipidea/otg.c | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index b02a80e..b09f3e0 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -49,7 +49,7 @@ u32 ci_read_otgsc(struct ci_hdrc *ci, u32 mask)
 	u32 val = ci->fake_otgsc;
 
 	cable_vbus = &ci->platdata->vbus_extcon;
-	cable_id = &ci->platdata->vbus_extcon;
+	cable_id = &ci->platdata->id_extcon;
 	if (!IS_ERR(cable_vbus->edev) || !IS_ERR(cable_id->edev)) {
 		if (!IS_ERR(cable_vbus->edev)) {
 			if (cable_vbus->changed)
@@ -78,6 +78,7 @@ u32 ci_read_otgsc(struct ci_hdrc *ci, u32 mask)
 			else
 				val &= ~OTGSC_ID;
 		}
+		val |= (OTGSC_IDIE | OTGSC_BSVIE);
 		return val;
 	} else if (ci->is_otg) { /* read otgsc from register */
 		return hw_read_otgsc(ci, mask);
@@ -129,23 +130,50 @@ enum ci_role ci_otg_role(struct ci_hdrc *ci)
 
 void ci_handle_vbus_change(struct ci_hdrc *ci)
 {
+	struct ci_hdrc_cable *vbus;
+
+	if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) {
+		vbus = &ci->platdata->vbus_extcon;
+
+		if (!IS_ERR(vbus->edev)) {
+			if (vbus->state)
+				usb_gadget_vbus_connect(&ci->gadget);
+			else
+				usb_gadget_vbus_disconnect(&ci->gadget);
+		}
+	}
+
 	if (ci->dp_always_pullup) {
 		usb_gadget_vbus_connect(&ci->gadget);
 		return;
 	}
 
-	if (ci_read_otgsc(ci, OTGSC_BSV))
-		usb_gadget_vbus_connect(&ci->gadget);
-	else
-		usb_gadget_vbus_disconnect(&ci->gadget);
+	if (!(ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG)) {
+		if (ci_read_otgsc(ci, OTGSC_BSV))
+			usb_gadget_vbus_connect(&ci->gadget);
+		else
+			usb_gadget_vbus_disconnect(&ci->gadget);
+	}
 }
 
 #define CI_VBUS_STABLE_TIMEOUT_MS 5000
 static void ci_handle_id_switch(struct ci_hdrc *ci)
 {
 	enum ci_role role = ci_otg_role(ci);
+	struct ci_hdrc_cable *id;
+
+	if (ci->platdata->flags & CI_HDRC_DUAL_ROLE_NOT_OTG) {
+		id = &ci->platdata->id_extcon;
 
-	if (role != ci->role) {
+		if (!IS_ERR(id->edev)) {
+			ci_role_stop(ci);
+
+			if (ci_role_start(ci, id->state ?
+					  CI_ROLE_GADGET : CI_ROLE_HOST))
+				dev_err(ci->dev, "Can't start %s role\n",
+					id->state ? "host" : "gadget");
+		}
+	} else if (role != ci->role) {
 		dev_dbg(ci->dev, "switching from %s to %s\n",
 			ci_role(ci)->name, ci->roles[role]->name);
 
-- 
2.8.2

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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux