OSDN Git Service

usb: gadget: composite: Split composite reset and disconnect
authorWesley Cheng <wcheng@codeaurora.org>
Tue, 29 Dec 2020 23:03:30 +0000 (15:03 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Jan 2021 15:45:50 +0000 (16:45 +0100)
Add a specific composite reset API to differentiate between disconnect and
reset events.  This is needed for adjusting the current draw accordingly
based on the USB battery charging specification.  The device is only allowed
to draw the 500/900 mA (HS/SS) while in the CONFIGURED state, and only 100 mA
in the connected and UNCONFIGURED state.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Link: https://lore.kernel.org/r/1609283011-21997-3-git-send-email-wcheng@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/composite.c
include/linux/usb/composite.h

index c6d455f..86e86a0 100644 (file)
@@ -2036,7 +2036,7 @@ done:
        return value;
 }
 
-void composite_disconnect(struct usb_gadget *gadget)
+static void __composite_disconnect(struct usb_gadget *gadget)
 {
        struct usb_composite_dev        *cdev = get_gadget_data(gadget);
        unsigned long                   flags;
@@ -2053,6 +2053,23 @@ void composite_disconnect(struct usb_gadget *gadget)
        spin_unlock_irqrestore(&cdev->lock, flags);
 }
 
+void composite_disconnect(struct usb_gadget *gadget)
+{
+       usb_gadget_vbus_draw(gadget, 0);
+       __composite_disconnect(gadget);
+}
+
+void composite_reset(struct usb_gadget *gadget)
+{
+       /*
+        * Section 1.4.13 Standard Downstream Port of the USB battery charging
+        * specification v1.2 states that a device connected on a SDP shall only
+        * draw at max 100mA while in a connected, but unconfigured state.
+        */
+       usb_gadget_vbus_draw(gadget, 100);
+       __composite_disconnect(gadget);
+}
+
 /*-------------------------------------------------------------------------*/
 
 static ssize_t suspended_show(struct device *dev, struct device_attribute *attr,
@@ -2373,7 +2390,7 @@ static const struct usb_gadget_driver composite_driver_template = {
        .unbind         = composite_unbind,
 
        .setup          = composite_setup,
-       .reset          = composite_disconnect,
+       .reset          = composite_reset,
        .disconnect     = composite_disconnect,
 
        .suspend        = composite_suspend,
index a2d229a..5646dad 100644 (file)
@@ -525,6 +525,8 @@ extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev,
 extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
 
 extern void composite_disconnect(struct usb_gadget *gadget);
+extern void composite_reset(struct usb_gadget *gadget);
+
 extern int composite_setup(struct usb_gadget *gadget,
                const struct usb_ctrlrequest *ctrl);
 extern void composite_suspend(struct usb_gadget *gadget);