diff mbox series

[v3,2/2] usb: gadget: composite: Draw 100mA current if not configured

Message ID 1677156121-30364-3-git-send-email-quic_prashk@quicinc.com (mailing list archive)
State Superseded
Headers show
Series Fix vbus draw of dwc3 gadget | expand

Commit Message

Prashanth K Feb. 23, 2023, 12:42 p.m. UTC
Currently we don't change the current value if device isn't in
configured state. But the battery charging specification says,
device can draw up to 100mA of current if its in unconfigured
state. Hence add a Vbus_draw work in composite_resume to draw
100mA if the device isn't configured.

Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
---
 drivers/usb/gadget/composite.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Thinh Nguyen Feb. 23, 2023, 8:10 p.m. UTC | #1
On Thu, Feb 23, 2023, Prashanth K wrote:
> Currently we don't change the current value if device isn't in
> configured state. But the battery charging specification says,

Can you provide the spec section also?

> device can draw up to 100mA of current if its in unconfigured

Is this related to being self-powered?

> state. Hence add a Vbus_draw work in composite_resume to draw
> 100mA if the device isn't configured.
> 
> Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
> ---
>  drivers/usb/gadget/composite.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 403563c..386140f 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -2449,6 +2449,10 @@ void composite_resume(struct usb_gadget *gadget)
>  			usb_gadget_clear_selfpowered(gadget);
>  
>  		usb_gadget_vbus_draw(gadget, maxpower);
> +	} else {
> +		maxpower = CONFIG_USB_GADGET_VBUS_DRAW;
> +		maxpower = min(maxpower, 100U);
> +		usb_gadget_vbus_draw(gadget, maxpower);
>  	}
>  
>  	cdev->suspended = 0;
> -- 
> 2.7.4
> 

Thanks,
Thinh
Prashanth K Feb. 24, 2023, 4:57 a.m. UTC | #2
On 24-02-23 01:40 am, Thinh Nguyen wrote:
> On Thu, Feb 23, 2023, Prashanth K wrote:
>> Currently we don't change the current value if device isn't in
>> configured state. But the battery charging specification says,
> 
> Can you provide the spec section also?
> 
1.2 Background
1.4.13 Standard Downstream Port

Did you mean to add these in the commit message?
>> device can draw up to 100mA of current if its in unconfigured
> 
> Is this related to being self-powered?
I think its applicable for bus-powered devices.

Thanks
Prashanth K
Thinh Nguyen Feb. 24, 2023, 6:38 p.m. UTC | #3
On Fri, Feb 24, 2023, Prashanth K wrote:
> 
> 
> On 24-02-23 01:40 am, Thinh Nguyen wrote:
> > On Thu, Feb 23, 2023, Prashanth K wrote:
> > > Currently we don't change the current value if device isn't in
> > > configured state. But the battery charging specification says,
> > 
> > Can you provide the spec section also?
> > 
> 1.2 Background
> 1.4.13 Standard Downstream Port
> 
> Did you mean to add these in the commit message?

Yes, it's better to have the reference in case we need to revisit this.

> > > device can draw up to 100mA of current if its in unconfigured
> > 
> > Is this related to being self-powered?

> I think its applicable for bus-powered devices.

No, I mean before configured state, is the device considered
self-powered? Since being self-powered means drawing 100mA or less, we
can use USB_SELF_POWER_VBUS_MAX_DRAW to provide more context. If it's
totally unrelated, then you can ignore this.

Thanks,
Thinh
Prashanth K Feb. 25, 2023, 6:35 a.m. UTC | #4
On 25-02-23 12:08 am, Thinh Nguyen wrote:
> On Fri, Feb 24, 2023, Prashanth K wrote:
>>
>>
>> On 24-02-23 01:40 am, Thinh Nguyen wrote:
>>> On Thu, Feb 23, 2023, Prashanth K wrote:
>>>> Currently we don't change the current value if device isn't in
>>>> configured state. But the battery charging specification says,
>>>
>>> Can you provide the spec section also?
>>>
>> 1.2 Background
>> 1.4.13 Standard Downstream Port
>>
>> Did you mean to add these in the commit message?
> 
> Yes, it's better to have the reference in case we need to revisit this.
I have added it in v4 patch, thanks for pointing it out.
> 
>>>> device can draw up to 100mA of current if its in unconfigured
>>>
>>> Is this related to being self-powered?
> 
>> I think its applicable for bus-powered devices.
> 
> No, I mean before configured state, is the device considered
> self-powered? Since being self-powered means drawing 100mA or less, we
> can use USB_SELF_POWER_VBUS_MAX_DRAW to provide more context. If it's
> totally unrelated, then you can ignore this.
> 
> Thanks,
> Thinh
As per my understanding, those are 2 different things. A self-powered 
device isn't allowed to draw more than 100mA. And an unconfigured device
isn't allowed to draw more than 100mA (in HS). One thing that I recently 
found out is that, as per usb3.0 spec, SS device can only draw up to 
150mA if its unconfigured state. So i have to check the speed and set 
the current values accordingly.

Thanks,
Prashanth K
Thinh Nguyen Feb. 27, 2023, 7:38 p.m. UTC | #5
On Sat, Feb 25, 2023, Prashanth K wrote:
> 
> 
> On 25-02-23 12:08 am, Thinh Nguyen wrote:
> > On Fri, Feb 24, 2023, Prashanth K wrote:
> > > 
> > > 
> > > On 24-02-23 01:40 am, Thinh Nguyen wrote:
> > > > On Thu, Feb 23, 2023, Prashanth K wrote:
> > > > > Currently we don't change the current value if device isn't in
> > > > > configured state. But the battery charging specification says,
> > > > 
> > > > Can you provide the spec section also?
> > > > 
> > > 1.2 Background
> > > 1.4.13 Standard Downstream Port
> > > 
> > > Did you mean to add these in the commit message?
> > 
> > Yes, it's better to have the reference in case we need to revisit this.
> I have added it in v4 patch, thanks for pointing it out.
> > 
> > > > > device can draw up to 100mA of current if its in unconfigured
> > > > 
> > > > Is this related to being self-powered?
> > 
> > > I think its applicable for bus-powered devices.
> > 
> > No, I mean before configured state, is the device considered
> > self-powered? Since being self-powered means drawing 100mA or less, we
> > can use USB_SELF_POWER_VBUS_MAX_DRAW to provide more context. If it's
> > totally unrelated, then you can ignore this.
> > 
> > Thanks,
> > Thinh
> As per my understanding, those are 2 different things. A self-powered device
> isn't allowed to draw more than 100mA. And an unconfigured device
> isn't allowed to draw more than 100mA (in HS). One thing that I recently
> found out is that, as per usb3.0 spec, SS device can only draw up to 150mA
> if its unconfigured state. So i have to check the speed and set the current
> values accordingly.

I see. Thanks for the info.

Thanks,
Thinh
diff mbox series

Patch

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 403563c..386140f 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -2449,6 +2449,10 @@  void composite_resume(struct usb_gadget *gadget)
 			usb_gadget_clear_selfpowered(gadget);
 
 		usb_gadget_vbus_draw(gadget, maxpower);
+	} else {
+		maxpower = CONFIG_USB_GADGET_VBUS_DRAW;
+		maxpower = min(maxpower, 100U);
+		usb_gadget_vbus_draw(gadget, maxpower);
 	}
 
 	cdev->suspended = 0;