2020-12-29 23:07:09

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH 0/3] Add vbus draw support to DWC3

Some devices are connected to standard downstream ports (SDP) and draw current
from them. The current rates are defined in the BC1.2 specification, and
highlights the different charge rates depending on the device state. The DWC3
gadget does not currently have a mechanism to notify external drivers about
how much current can be drawn.

The current rates are notified by the USB gadget layer, and the DWC3 gadget will
propagate this potentially to external charger drivers. Also, the USB gadget
needs to be fixed to only allow 100mA current draw when receiving a bus reset
from the host, as the BC1.2 specification states that this is the max current
draw possible when in the connected and unconfigured state.

Wesley Cheng (3):
usb: dwc3: gadget: Introduce a DWC3 VBUS draw callback
usb: gadget: composite: Split composite reset and disconnect
usb: gadget: configfs: Add a specific configFS reset callback

drivers/usb/dwc3/gadget.c | 11 +++++++++++
drivers/usb/gadget/composite.c | 21 +++++++++++++++++++--
drivers/usb/gadget/configfs.c | 24 +++++++++++++++++++++++-
include/linux/usb/composite.h | 2 ++
4 files changed, 55 insertions(+), 3 deletions(-)

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2020-12-29 23:08:05

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH 3/3] usb: gadget: configfs: Add a specific configFS reset callback

In order for configFS based USB gadgets to set the proper charge current
for bus reset scenarios, expose a separate reset callback to set the
current to 100mA based on the USB battery charging specification.

Reviewed-by: Peter Chen <[email protected]>
Signed-off-by: Wesley Cheng <[email protected]>
---
drivers/usb/gadget/configfs.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 56051bb97349..80ca7ff2fb97 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1481,6 +1481,28 @@ static void configfs_composite_disconnect(struct usb_gadget *gadget)
spin_unlock_irqrestore(&gi->spinlock, flags);
}

+static void configfs_composite_reset(struct usb_gadget *gadget)
+{
+ struct usb_composite_dev *cdev;
+ struct gadget_info *gi;
+ unsigned long flags;
+
+ cdev = get_gadget_data(gadget);
+ if (!cdev)
+ return;
+
+ gi = container_of(cdev, struct gadget_info, cdev);
+ spin_lock_irqsave(&gi->spinlock, flags);
+ cdev = get_gadget_data(gadget);
+ if (!cdev || gi->unbind) {
+ spin_unlock_irqrestore(&gi->spinlock, flags);
+ return;
+ }
+
+ composite_reset(gadget);
+ spin_unlock_irqrestore(&gi->spinlock, flags);
+}
+
static void configfs_composite_suspend(struct usb_gadget *gadget)
{
struct usb_composite_dev *cdev;
@@ -1530,7 +1552,7 @@ static const struct usb_gadget_driver configfs_driver_template = {
.unbind = configfs_composite_unbind,

.setup = configfs_composite_setup,
- .reset = configfs_composite_disconnect,
+ .reset = configfs_composite_reset,
.disconnect = configfs_composite_disconnect,

.suspend = configfs_composite_suspend,
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2021-01-04 15:47:44

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3/3] usb: gadget: configfs: Add a specific configFS reset callback

On Tue, Dec 29, 2020 at 03:03:31PM -0800, Wesley Cheng wrote:
> In order for configFS based USB gadgets to set the proper charge current
> for bus reset scenarios, expose a separate reset callback to set the
> current to 100mA based on the USB battery charging specification.
>
> Reviewed-by: Peter Chen <[email protected]>
> Signed-off-by: Wesley Cheng <[email protected]>
> ---
> drivers/usb/gadget/configfs.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
> index 56051bb97349..80ca7ff2fb97 100644
> --- a/drivers/usb/gadget/configfs.c
> +++ b/drivers/usb/gadget/configfs.c
> @@ -1481,6 +1481,28 @@ static void configfs_composite_disconnect(struct usb_gadget *gadget)
> spin_unlock_irqrestore(&gi->spinlock, flags);
> }
>
> +static void configfs_composite_reset(struct usb_gadget *gadget)
> +{
> + struct usb_composite_dev *cdev;
> + struct gadget_info *gi;
> + unsigned long flags;
> +
> + cdev = get_gadget_data(gadget);
> + if (!cdev)
> + return;
> +
> + gi = container_of(cdev, struct gadget_info, cdev);
> + spin_lock_irqsave(&gi->spinlock, flags);
> + cdev = get_gadget_data(gadget);
> + if (!cdev || gi->unbind) {
> + spin_unlock_irqrestore(&gi->spinlock, flags);
> + return;
> + }
> +
> + composite_reset(gadget);
> + spin_unlock_irqrestore(&gi->spinlock, flags);
> +}
> +
> static void configfs_composite_suspend(struct usb_gadget *gadget)
> {
> struct usb_composite_dev *cdev;
> @@ -1530,7 +1552,7 @@ static const struct usb_gadget_driver configfs_driver_template = {
> .unbind = configfs_composite_unbind,
>
> .setup = configfs_composite_setup,
> - .reset = configfs_composite_disconnect,
> + .reset = configfs_composite_reset,
> .disconnect = configfs_composite_disconnect,
>
> .suspend = configfs_composite_suspend,
> --
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>

So this changes the existing userspace functionality? What will break
because of this now unexpected change?

thanks,

greg k-h

2021-01-04 19:06:33

by Wesley Cheng

[permalink] [raw]
Subject: Re: [PATCH 3/3] usb: gadget: configfs: Add a specific configFS reset callback



On 1/4/2021 7:45 AM, Greg KH wrote:
> On Tue, Dec 29, 2020 at 03:03:31PM -0800, Wesley Cheng wrote:
>> In order for configFS based USB gadgets to set the proper charge current
>> for bus reset scenarios, expose a separate reset callback to set the
>> current to 100mA based on the USB battery charging specification.
>>
>> Reviewed-by: Peter Chen <[email protected]>
>> Signed-off-by: Wesley Cheng <[email protected]>
>> ---
>> drivers/usb/gadget/configfs.c | 24 +++++++++++++++++++++++-
>> 1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
>> index 56051bb97349..80ca7ff2fb97 100644
>> --- a/drivers/usb/gadget/configfs.c
>> +++ b/drivers/usb/gadget/configfs.c
>> @@ -1481,6 +1481,28 @@ static void configfs_composite_disconnect(struct usb_gadget *gadget)
>> spin_unlock_irqrestore(&gi->spinlock, flags);
>> }
>>
>> +static void configfs_composite_reset(struct usb_gadget *gadget)
>> +{
>> + struct usb_composite_dev *cdev;
>> + struct gadget_info *gi;
>> + unsigned long flags;
>> +
>> + cdev = get_gadget_data(gadget);
>> + if (!cdev)
>> + return;
>> +
>> + gi = container_of(cdev, struct gadget_info, cdev);
>> + spin_lock_irqsave(&gi->spinlock, flags);
>> + cdev = get_gadget_data(gadget);
>> + if (!cdev || gi->unbind) {
>> + spin_unlock_irqrestore(&gi->spinlock, flags);
>> + return;
>> + }
>> +
>> + composite_reset(gadget);
>> + spin_unlock_irqrestore(&gi->spinlock, flags);
>> +}
>> +
>> static void configfs_composite_suspend(struct usb_gadget *gadget)
>> {
>> struct usb_composite_dev *cdev;
>> @@ -1530,7 +1552,7 @@ static const struct usb_gadget_driver configfs_driver_template = {
>> .unbind = configfs_composite_unbind,
>>
>> .setup = configfs_composite_setup,
>> - .reset = configfs_composite_disconnect,
>> + .reset = configfs_composite_reset,
>> .disconnect = configfs_composite_disconnect,
>>
>> .suspend = configfs_composite_suspend,
>> --
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>> a Linux Foundation Collaborative Project
>>
>
> So this changes the existing userspace functionality? What will break
> because of this now unexpected change?
>
> thanks,
>
> greg k-h
>

Hi Greg,

Happy new years! This wouldn't affect the userspace interaction with
configFS, as this is modifying the reset callback for the UDC core. The
reset callback is only executed during usb_gadget_udc_reset(), which is
specifically run when vendor UDC drivers (i.e. DWC3 gadget) receive a
USB bus reset interrupt. This is similar to the composite.c patch,
because for configFS based gadgets, they do not directly register the
USB composite ops and have their own routines.

Thanks
Wesley Cheng

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project