Skip to contentSkip to conversation

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

PATCH In review Peter Chen 2 participants 3 messages Oct 21, 2015 – Oct 22, 2015

Subsystems (3)
lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 usb: chipidea: otg: gadget module load and unload support

From: Li Jun <[email protected]>

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

(Peter: it fixes a bug that the unload/reload gadget driver can't work
well at OTG FSM mode)
Cc: <[email protected]> #v4.0+

---
 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 · 1 line
1.9.1
#1 lore raw

Hello

Quoted 43 lines · Peter Chen

From: Li Jun <[email protected]>

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

(Peter: it fixes a bug that the unload/reload gadget driver can't work
well at OTG FSM mode)
Cc: <[email protected]> #v4.0+

---
  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 have confirmed this patch resolves my issue with gadget module load/unload please feel free to add my Tested-by

Thanks,
Jiada

author
#2 lore raw
Quoted 49 lines · Jiada Wang

Hello

Quoted 45 lines · Peter Chen

From: Li Jun <[email protected]>

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

(Peter: it fixes a bug that the unload/reload gadget driver can't work
well at OTG FSM mode)
Cc: <[email protected]> #v4.0+

---
 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 8 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 have confirmed this patch resolves my issue with gadget module load/unload please feel free to add my Tested-by

Thanks, I had tested it before I sent, it fixed the problem. Since I have already added tag for it, I can't add your tested-by.

Signature · 2 lines
Best Regards,
Peter Chen