Skip to contentSkip to conversation

usb: dwc3: gadget: call gadget driver's ->suspend/->resume

PATCH In review David Cohen 3 participants 11 messages Apr 17, 2015 – Apr 27, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: gadget: call gadget driver's ->suspend/->resume

From: Felipe Balbi <[email protected]>

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.
I propose to backport it over there as well.

BR, David
---

 drivers/usb/dwc3/gadget.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/usb/dwc3/gadget.c +35 -0
index 8f6738d46b14..1bb752736c32 100644
@@ -2012,6 +2012,24 @@ static void dwc3_disconnect_gadget(struct dwc3 *dwc)
 	}
 }
 
+static void dwc3_suspend_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->suspend(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
+static void dwc3_resume_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->resume(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
 static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum)
 {
 	struct dwc3_ep *dep;
@@ -2391,6 +2409,23 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
 
 	dwc->link_state = next;
 
+	switch (next) {
+	case DWC3_LINK_STATE_U1:
+		if (dwc->speed == USB_SPEED_SUPER)
+			dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_U2:
+	case DWC3_LINK_STATE_U3:
+		dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_RESUME:
+		dwc3_resume_gadget(dwc);
+		break;
+	default:
+		/* do nothing */
+		break;
+	}
+
 	dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state);
 }
 
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 10 lines · David Cohen

From: Felipe Balbi <[email protected]>

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

Quoted 8 lines

---

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.
I propose to backport it over there as well.

What is the git commit id of the patch in Linus's tree?

thanks,

greg k-h

#2 lore raw

Hi Greg,

Quoted 13 lines · Greg KH
Quoted 12 lines · David Cohen

From: Felipe Balbi <[email protected]>

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 6 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.
I propose to backport it over there as well.

What is the git commit id of the patch in Linus's tree?

Sorry for the missing info. As Felipe replied, this is the commit:
Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9

I'm resending it to fix the commit message and add a second patch as well.

Br, David

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
In reply to David Cohen
Quoted 1 line · David Cohen

From: Felipe Balbi <[email protected]>

missing the required:

[ Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9 ]

Quoted 9 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

Quoted 7 lines

---

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

Quoted 13 lines

I propose to backport it over there as well.

BR, David
---

 drivers/usb/dwc3/gadget.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/usb/dwc3/gadget.c +0 -0
index 8f6738d46b14..1bb752736c32 100644

drivers/usb/dwc3/gadget.c static void dwc3_disconnect_gadget(struct dwc3 *dwc) · line 2017

Quoted 6 lines
drivers/usb/dwc3/gadget.c +3 -0
@@ -2012,6 +2012,24 @@ static void dwc3_disconnect_gadget(struct dwc3 *dwc)
 	}
 }
 
+static void dwc3_suspend_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {

you also need Dan Carperter's commit which fixes this cut & paste error. That's commit 73a30bfc0d526db899033165db6f95c427e70505

Quoted 41 lines
drivers/usb/dwc3/gadget.c +32 -0
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->suspend(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
+static void dwc3_resume_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->resume(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
 static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum)
 {
 	struct dwc3_ep *dep;
@@ -2391,6 +2409,23 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
 
 	dwc->link_state = next;
 
+	switch (next) {
+	case DWC3_LINK_STATE_U1:
+		if (dwc->speed == USB_SPEED_SUPER)
+			dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_U2:
+	case DWC3_LINK_STATE_U3:
+		dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_RESUME:
+		dwc3_resume_gadget(dwc);
+		break;
+	default:
+		/* do nothing */
+		break;
+	}
+
 	dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state);
 }
Signature · 1 line
balbi
#4 lore raw
Quoted 43 lines · Felipe Balbi
Quoted 1 line · David Cohen

From: Felipe Balbi <[email protected]>

missing the required:

[ Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9 ]

Quoted 9 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

Quoted 7 lines

---

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

Quoted 16 lines

I propose to backport it over there as well.

BR, David
---

 drivers/usb/dwc3/gadget.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/usb/dwc3/gadget.c +0 -0
index 8f6738d46b14..1bb752736c32 100644
@@ -2012,6 +2012,24 @@ static void dwc3_disconnect_gadget(struct dwc3 *dwc)
 	}
 }
 
Quoted 5 lines

drivers/usb/dwc3/gadget.c static void dwc3_disconnect_gadget(struct dwc3 *dwc) · line 2017

Quoted 3 lines
drivers/usb/dwc3/gadget.c +3 -0
+static void dwc3_suspend_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {

you also need Dan Carperter's commit which fixes this cut & paste error.

That's Carpenter, sorry.

Signature · 1 line
balbi
#5 lore raw
In reply to Felipe Balbi

Hi Felipe,

Quoted 18 lines · Felipe Balbi
Quoted 1 line · David Cohen

From: Felipe Balbi <[email protected]>

missing the required:

[ Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9 ]

Quoted 11 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

4. On making Host active (ER: 500mA):
500mA

Quoted 17 lines
Quoted 17 lines

I propose to backport it over there as well.

BR, David
---

 drivers/usb/dwc3/gadget.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
drivers/usb/dwc3/gadget.c +0 -0
index 8f6738d46b14..1bb752736c32 100644
@@ -2012,6 +2012,24 @@ static void dwc3_disconnect_gadget(struct dwc3 *dwc)
 	}
 }
 
Quoted 6 lines

drivers/usb/dwc3/gadget.c static void dwc3_disconnect_gadget(struct dwc3 *dwc) · line 2017

Quoted 3 lines
drivers/usb/dwc3/gadget.c +3 -0
+static void dwc3_suspend_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {

you also need Dan Carperter's commit which fixes this cut & paste error. That's commit 73a30bfc0d526db899033165db6f95c427e70505

Thanks. I'll add that to my next try.

Br, David

#6 lore raw

Hi,

Quoted 39 lines · David Cohen
Quoted 18 lines · Felipe Balbi
Quoted 1 line · David Cohen

From: Felipe Balbi <[email protected]>

missing the required:

[ Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9 ]

Quoted 11 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

Quoted 6 lines

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

4. On making Host active (ER: 500mA):

   500mA

But we don't support Battery Charging with dwc3 as of now :-) In fact, just note that none of the BC registers are even defined in the current driver anywhere. Seems like you should cherry-pick these to your vendor tree, but v3.14 vanilla, because it doesn't support BC1.2, can't be claimed to be at fault, right ?

I'll leave the final decision to Greg and I don't really oppose having both patches on v3.14-stable, but this is not a bug fix in my view.

Signature · 1 line
balbi
#7 lore raw
Quoted 1 line · Felipe Balbi

Hi,

Hi Felipe,

Quoted 45 lines · David Cohen
Quoted 43 lines · Felipe Balbi
Quoted 18 lines · David Cohen
Quoted 1 line

From: Felipe Balbi <[email protected]>

missing the required:

[ Upstream commit bc5ba2e0b829c9397f96df1191c7d2319ebc36d9 ]

Quoted 11 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

Quoted 8 lines
Quoted 2 lines

4. On making Host active (ER: 500mA):

   500mA

But we don't support Battery Charging with dwc3 as of now :-) In fact, just note that none of the BC registers are even defined in the current driver anywhere. Seems like you should cherry-pick these to your vendor tree, but v3.14 vanilla, because it doesn't support BC1.2, can't be claimed to be at fault, right ?

We could call it a missing feature that could lead to a potential bug :) By your own comment, he "must" was stressed out:
'''
When going into bus suspend/resume we _must_
call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature
which has been missing forever.
'''

Since v3.14 is a LTS kernel and the changes are safe, it's worth to consider.

Quoted 3 lines

I'll leave the final decision to Greg and I don't really oppose having both patches on v3.14-stable, but this is not a bug fix in my view.

Thanks. I appreciate your feedback.

BR, David

PS: FWIW implementing features or fixing bugs aren't much different tasks:
https://geekwhisperin.files.wordpress.com/2009/09/bug-vs-feature.jpg

#8 lore raw

Hi,

Quoted 37 lines · David Cohen
Quoted 37 lines
Quoted 36 lines
Quoted 10 lines
Quoted 10 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

4. On making Host active (ER: 500mA):

   500mA
Quoted 8 lines
Quoted 5 lines

But we don't support Battery Charging with dwc3 as of now :-) In fact, just note that none of the BC registers are even defined in the current driver anywhere. Seems like you should cherry-pick these to your vendor tree, but v3.14 vanilla, because it doesn't support BC1.2, can't be claimed to be at fault, right ?

We could call it a missing feature that could lead to a potential bug :) By your own comment, he "must" was stressed out:

sure it was because they really must be called :-) However, the only actual problem that arises from not calling them is with something that's not supported :-)

Quoted 8 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.
'''

Since v3.14 is a LTS kernel and the changes are safe, it's worth to consider.

definitely worth to consider, but not as something that fixes BC1.2 because that's, as said, not supported in any public tree :-)

Quoted 9 lines
Quoted 2 lines

I'll leave the final decision to Greg and I don't really oppose having both patches on v3.14-stable, but this is not a bug fix in my view.

Thanks. I appreciate your feedback.

BR, David

PS: FWIW implementing features or fixing bugs aren't much different tasks:
https://geekwhisperin.files.wordpress.com/2009/09/bug-vs-feature.jpg

Yes, I used to have that on my office door ;-)

Signature · 1 line
balbi
#9 lore raw
Quoted 1 line · Felipe Balbi

Hi,

Hi Felipe,

Quoted 58 lines · David Cohen
Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 10 lines
Quoted 10 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

4. On making Host active (ER: 500mA):

   500mA
Quoted 8 lines
Quoted 5 lines

But we don't support Battery Charging with dwc3 as of now :-) In fact, just note that none of the BC registers are even defined in the current driver anywhere. Seems like you should cherry-pick these to your vendor tree, but v3.14 vanilla, because it doesn't support BC1.2, can't be claimed to be at fault, right ?

We could call it a missing feature that could lead to a potential bug :) By your own comment, he "must" was stressed out:

sure it was because they really must be called :-) However, the only actual problem that arises from not calling them is with something that's not supported :-)

Quoted 6 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.
'''

Quoted 5 lines
Quoted 2 lines

Since v3.14 is a LTS kernel and the changes are safe, it's worth to consider.

definitely worth to consider, but not as something that fixes BC1.2 because that's, as said, not supported in any public tree :-)

Thanks for the reply.
The gadget having this issue is really out-of-tree (android gadget). I could do 2 next steps:
1) I could drop android gadget and try to reproduce this issue using legacy g_ffs, which supports adbd as well.
2) I could propose this change directly on google's android 3.14 tree instead.

Would you prefer one of those?

Thanks,

David

#10 lore raw
Quoted 77 lines · David Cohen
Quoted 1 line · Felipe Balbi

Hi,

Hi Felipe,

Quoted 58 lines · David Cohen
Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 10 lines
Quoted 10 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.

---

Quoted 8 lines
Quoted 5 lines

Hi,

This patch was introduced on v3.15.
But the issue it fixes already existed on v3.14 and v3.14 is a long term support version.

Can you show me a log of this breaking anywhere ? Why do you consider this a bug fix ? What sort of drawbacks did you notice ?

We're seeing BC1.2 compliance test failure. I borrowed this info from the bug report :)

1. BC1.2 compliance testing - SDP2.0
-----------------------------------------------
1. On Connect to active Host (Expected result: 100mA to 500mA):
Actual result 100mA to 500mA

2. On Host Suspend (ER: Fall back to 0mA):
not falling back to 0mA, remains at 500mA

3. On Connect to Suspended Host (ER: 100mA to 0mA):
cable-props shown as 100mA, which means drawing a current of 100mA from Suspended Host

4. On making Host active (ER: 500mA):

   500mA
Quoted 8 lines
Quoted 5 lines

But we don't support Battery Charging with dwc3 as of now :-) In fact, just note that none of the BC registers are even defined in the current driver anywhere. Seems like you should cherry-pick these to your vendor tree, but v3.14 vanilla, because it doesn't support BC1.2, can't be claimed to be at fault, right ?

We could call it a missing feature that could lead to a potential bug :) By your own comment, he "must" was stressed out:

sure it was because they really must be called :-) However, the only actual problem that arises from not calling them is with something that's not supported :-)

Quoted 6 lines

When going into bus suspend/resume we _must_ call gadget driver's ->suspend/->resume callbacks accordingly. This patch implements that very feature which has been missing forever.
'''

Quoted 5 lines
Quoted 2 lines

Since v3.14 is a LTS kernel and the changes are safe, it's worth to consider.

definitely worth to consider, but not as something that fixes BC1.2 because that's, as said, not supported in any public tree :-)

Thanks for the reply.
The gadget having this issue is really out-of-tree (android gadget). I could do 2 next steps:
1) I could drop android gadget and try to reproduce this issue using legacy g_ffs, which supports adbd as well.
2) I could propose this change directly on google's android 3.14 tree instead.

Quoted 1 line

Would you prefer one of those?

hehe, I'll let Greg decide, I'm not against the patch, as I said before, but I'm also not entirely sure it fits within stable rules ;-)

cheers

Signature · 1 line
balbi