gadget:Update the default vbus draw
authora17671 <a17671@motorola.com>
Thu, 29 Nov 2018 07:15:08 +0000 (15:15 +0800)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:30:24 +0000 (17:30 +0800)
Update the highspeed vbus draw to 500mA
And super speed vbus draw to 900mA

Change-Id: I677c8a1c2ea3b5a9f81ddab0c91179d3b4b3e3f4
Signed-off-by: a17671 <a17671@motorola.com>
Reviewed-on: https://gerrit.mot.com/1275669
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Reviewed-by: Wei Xu <xuwei9@mt.com>
Submit-Approved: Jira Key

drivers/usb/gadget/composite.c

index a366582e92bc8331092160d3234d64f60c545cfd..e1973e0e446fed4094f8dd28689922da911a37fe 100644 (file)
 #include <asm/unaligned.h>
 
 #include "u_os_desc.h"
+#define SSUSB_GADGET_VBUS_DRAW 900 /* in mA */
+#define SSUSB_GADGET_VBUS_DRAW_UNITS 8
+#define HSUSB_GADGET_VBUS_DRAW_UNITS 2
+
+/*
+ * Based on enumerated USB speed, draw power with set_config and resume
+ * HSUSB: 500mA, SSUSB: 900mA
+ */
+#define USB_VBUS_DRAW(speed)\
+       (speed == USB_SPEED_SUPER ?\
+        SSUSB_GADGET_VBUS_DRAW : CONFIG_USB_GADGET_VBUS_DRAW)
 
 /**
  * struct usb_os_string - represents OS String to be reported by a gadget
@@ -432,19 +443,15 @@ EXPORT_SYMBOL_GPL(usb_interface_id);
 static u8 encode_bMaxPower(enum usb_device_speed speed,
                struct usb_configuration *c)
 {
-       unsigned val;
+       unsigned int val = CONFIG_USB_GADGET_VBUS_DRAW;
 
-       if (c->MaxPower)
-               val = c->MaxPower;
-       else
-               val = CONFIG_USB_GADGET_VBUS_DRAW;
-       if (!val)
-               return 0;
        switch (speed) {
        case USB_SPEED_SUPER:
-               return DIV_ROUND_UP(val, 8);
+               /* with super-speed report 900mA */
+               val = SSUSB_GADGET_VBUS_DRAW;
+               return (u8)(val / SSUSB_GADGET_VBUS_DRAW_UNITS);
        default:
-               return DIV_ROUND_UP(val, 2);
+               return DIV_ROUND_UP(val, HSUSB_GADGET_VBUS_DRAW_UNITS);
        }
 }