Skip to contentSkip to conversation

usb: chipidea: udc: clear vbus_active flag in udc_stop

PATCH In review Jiada Wang 2 participants 6 messages Oct 20, 2015

Subsystems (2)
lore
Share & tools
lore

Jiada Wang

author
#0 lore raw

PATCH 1/1 usb: chipidea: udc: clear vbus_active flag in udc_stop

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
 drivers/usb/chipidea/udc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +1 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	spin_lock_irqsave(&ci->lock, flags);
 
 	if (ci->vbus_active) {
+		ci->vbus_active = 0;
 		hw_device_state(ci, 0);
 		if (ci->platdata->notify_event)
 			ci->platdata->notify_event(ci,
Signature · 1 line
2.4.5
#1 lore raw
Quoted 28 lines · Jiada Wang

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
 drivers/usb/chipidea/udc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +1 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	spin_lock_irqsave(&ci->lock, flags);
 
 	if (ci->vbus_active) {
+		ci->vbus_active = 0;
 		hw_device_state(ci, 0);
 		if (ci->platdata->notify_event)
 			ci->platdata->notify_event(ci,
Signature · 1 line
2.4.5

This flag will be handled by vbus interrupt, would you please explain more what problem you have met?

Signature · 2 lines
Best Regards,
Peter Chen
author
#2 lore raw

Hi

Quoted 21 lines · Peter Chen
Quoted 20 lines · Jiada Wang

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
  drivers/usb/chipidea/udc.c | 1 +
  1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
  	spin_lock_irqsave(&ci->lock, flags);
 
Quoted 11 lines
Quoted 8 lines
drivers/usb/chipidea/udc.c +1 -1
  	if (ci->vbus_active) {
+		ci->vbus_active = 0;
  		hw_device_state(ci, 0);
  		if (ci->platdata->notify_event)
  			ci->platdata->notify_event(ci,
--

2.4.5

This flag will be handled by vbus interrupt, would you please explain more what problem you have met?

the actual issue I had is,
build kernel with USB_OTG_FSM enabled,
keep usb cable plugged,
load/unload USB gadget module (for example I tried g_zero or g_serial), after unload gadget module once, then the status of vbus_active is not correct,
this causes host machine failed to detect gadget device when later gadget device module is loaded again.

Thanks,
Jiada

Quoted 1 line
Acked-by
#3 lore raw
Quoted 35 lines · Jiada Wang

Hi

Quoted 21 lines · Peter Chen
Quoted 20 lines · Jiada Wang

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
 drivers/usb/chipidea/udc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	spin_lock_irqsave(&ci->lock, flags);
 
Quoted 11 lines
Quoted 8 lines
drivers/usb/chipidea/udc.c +1 -1
 	if (ci->vbus_active) {
+		ci->vbus_active = 0;
 		hw_device_state(ci, 0);
 		if (ci->platdata->notify_event)
 			ci->platdata->notify_event(ci,
--

2.4.5

This flag will be handled by vbus interrupt, would you please explain more what problem you have met?

Quoted 10 lines

the actual issue I had is,
build kernel with USB_OTG_FSM enabled,
keep usb cable plugged,
load/unload USB gadget module (for example I tried g_zero or g_serial), after unload gadget module once, then the status of vbus_active is not correct,
this causes host machine failed to detect gadget device when later gadget device module is loaded again.

ci->vbus_active is only used at non-fsm mode, would you please try below fix?

usb: chipidea: otg: gadget module load and unload support

This patch is to support load and unload gadget driver in full OTG mode.

---
 drivers/usb/chipidea/udc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/usb/chipidea/udc.c +17 -0
index e19d8b8..67cfa04 100644
@@ -1755,6 +1755,22 @@ static int ci_udc_start(struct usb_gadget *gadget,
 	return retval;
 }
 
+static void ci_udc_stop_for_otg_fsm(struct ci_hdrc *ci)
+{
+	if (!ci_otg_is_fsm_mode(ci))
+		return;
+
+	mutex_lock(&ci->fsm.lock);
+	if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) {
+		ci->fsm.a_bidl_adis_tmout = 1;
+		ci_hdrc_otg_fsm_start(ci);
+	} else if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) {
+		ci->fsm.protocol = PROTO_UNDEF;
+		ci->fsm.otg->state = OTG_STATE_UNDEFINED;
+	}
+	mutex_unlock(&ci->fsm.lock);
+}
+
 /**
  * ci_udc_stop: unregister a gadget driver
  */
@@ -1779,6 +1795,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	ci->driver = NULL;
 	spin_unlock_irqrestore(&ci->lock, flags);
 
+	ci_udc_stop_for_otg_fsm(ci);
 	return 0;
 }
 
Signature · 6 lines
1.9.1

-- 

Best Regards,
Peter Chen
author
#4 lore raw

Hi

Quoted 89 lines · Peter Chen
Quoted 35 lines · Jiada Wang

Hi

Quoted 21 lines · Peter Chen
Quoted 20 lines · Jiada Wang

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
  drivers/usb/chipidea/udc.c | 1 +
  1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
  	spin_lock_irqsave(&ci->lock, flags);
 
Quoted 11 lines
Quoted 8 lines
drivers/usb/chipidea/udc.c +1 -1
  	if (ci->vbus_active) {
+		ci->vbus_active = 0;
  		hw_device_state(ci, 0);
  		if (ci->platdata->notify_event)
  			ci->platdata->notify_event(ci,
--

2.4.5

This flag will be handled by vbus interrupt, would you please explain more what problem you have met?

Quoted 10 lines

the actual issue I had is,
build kernel with USB_OTG_FSM enabled,
keep usb cable plugged,
load/unload USB gadget module (for example I tried g_zero or g_serial), after unload gadget module once, then the status of vbus_active is not correct,
this causes host machine failed to detect gadget device when later gadget device module is loaded again.

ci->vbus_active is only used at non-fsm mode, would you please try below fix?

usb: chipidea: otg: gadget module load and unload support

This patch is to support load and unload gadget driver in full OTG mode.

---
  drivers/usb/chipidea/udc.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
drivers/usb/chipidea/udc.c +16 -0
index e19d8b8..67cfa04 100644
@@ -1755,6 +1755,22 @@ static int ci_udc_start(struct usb_gadget *gadget,
  	return retval;
  }
 
+static void ci_udc_stop_for_otg_fsm(struct ci_hdrc *ci)
+{
+	if (!ci_otg_is_fsm_mode(ci))
+		return;
+
+	mutex_lock(&ci->fsm.lock);
+	if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) {
+		ci->fsm.a_bidl_adis_tmout = 1;
+		ci_hdrc_otg_fsm_start(ci);
+	} else if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) {
+		ci->fsm.protocol = PROTO_UNDEF;
+		ci->fsm.otg->state = OTG_STATE_UNDEFINED;
+	}
+	mutex_unlock(&ci->fsm.lock);
+}
+
  /**
   * ci_udc_stop: unregister a gadget driver
   */

drivers/usb/chipidea/udc.c static int ci_udc_stop(struct usb_gadget *gadget) · line 1801

Quoted 7 lines
drivers/usb/chipidea/udc.c +1 -0
@@ -1779,6 +1795,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
  	ci->driver = NULL;
  	spin_unlock_irqrestore(&ci->lock, flags);
 
+	ci_udc_stop_for_otg_fsm(ci);
  	return 0;
  }
 

I will test with this patch and come back with the result, has this patch been submitted to community?

Thanks,
Jiada

#5 lore raw
Quoted 94 lines · Jiada Wang

Hi

Quoted 91 lines · Peter Chen
Quoted 35 lines · Jiada Wang

Hi

Quoted 21 lines · Peter Chen
Quoted 20 lines · Jiada Wang

Currently in udc_stop, if vbus_active flag is true, all USB activities will be stopped, but vbus_active flag is still left to be true, this causes issue, when afterwards driver tries to connect gadget device to host, But due to the uncleared vbus_active, some necessary setup steps are skipped.

This patch clears vbus_active flag in udc_stop callback.

---
 drivers/usb/chipidea/udc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/chipidea/udc.c +0 -0
index 8223fe7..b9ac228 100644
@@ -1762,6 +1762,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	spin_lock_irqsave(&ci->lock, flags);
 
Quoted 11 lines
Quoted 8 lines
drivers/usb/chipidea/udc.c +1 -1
 	if (ci->vbus_active) {
+		ci->vbus_active = 0;
 		hw_device_state(ci, 0);
 		if (ci->platdata->notify_event)
 			ci->platdata->notify_event(ci,
--

2.4.5

This flag will be handled by vbus interrupt, would you please explain more what problem you have met?

Quoted 10 lines

the actual issue I had is,
build kernel with USB_OTG_FSM enabled,
keep usb cable plugged,
load/unload USB gadget module (for example I tried g_zero or g_serial), after unload gadget module once, then the status of vbus_active is not correct,
this causes host machine failed to detect gadget device when later gadget device module is loaded again.

ci->vbus_active is only used at non-fsm mode, would you please try below fix?

usb: chipidea: otg: gadget module load and unload support

This patch is to support load and unload gadget driver in full OTG mode.

---
 drivers/usb/chipidea/udc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/usb/chipidea/udc.c +16 -0
index e19d8b8..67cfa04 100644
@@ -1755,6 +1755,22 @@ static int ci_udc_start(struct usb_gadget *gadget,
 	return retval;
 }
 
+static void ci_udc_stop_for_otg_fsm(struct ci_hdrc *ci)
+{
+	if (!ci_otg_is_fsm_mode(ci))
+		return;
+
+	mutex_lock(&ci->fsm.lock);
+	if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) {
+		ci->fsm.a_bidl_adis_tmout = 1;
+		ci_hdrc_otg_fsm_start(ci);
+	} else if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) {
+		ci->fsm.protocol = PROTO_UNDEF;
+		ci->fsm.otg->state = OTG_STATE_UNDEFINED;
+	}
+	mutex_unlock(&ci->fsm.lock);
+}
+
 /**
  * ci_udc_stop: unregister a gadget driver
  */
@@ -1779,6 +1795,7 @@ static int ci_udc_stop(struct usb_gadget *gadget)
 	ci->driver = NULL;
 	spin_unlock_irqrestore(&ci->lock, flags);
 
Quoted 9 lines

drivers/usb/chipidea/udc.c static int ci_udc_stop(struct usb_gadget *gadget) · line 1801

Quoted 5 lines
drivers/usb/chipidea/udc.c +1 -0
+	ci_udc_stop_for_otg_fsm(ci);
 	return 0;
 }
 

I will test with this patch and come back with the result, has this patch been submitted to community?

I am afraid it is not, please add your tested-by if it fixes your problem, I will queue it as a bug-fix.

Signature · 2 lines
Best Regards,
Peter Chen