Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6cadaa8 authored by Mayank Rana's avatar Mayank Rana
Browse files

usb: gadget: Draw 900mA current when enumerating in super speed mode



Currently 500mA is used as max allowable current to draw with USB SDP
case in both super speed and high speed mode. In super speed mode it
is allowed to draw 900mA current. Hence update allowable current to
draw based on USB connection speed. This change doesn't consider any
configuration based allowable max current.

Change-Id: Iae9ecf586135b0a2064e7d5e6e8fa3d8e7e4fb70
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent 13e5c159
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@
#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

/**
 * struct usb_os_string - represents OS String to be reported by a gadget
@@ -519,19 +522,15 @@ EXPORT_SYMBOL(usb_func_ep_queue);
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);
	}
}

@@ -934,8 +933,12 @@ static int set_config(struct usb_composite_dev *cdev,
		}
	}

	/* when we return, be sure our power usage is valid */
	power = c->MaxPower ? c->MaxPower : CONFIG_USB_GADGET_VBUS_DRAW;
	/* Allow 900mA to draw with Super-Speed */
	if (gadget->speed == USB_SPEED_SUPER)
		power = SSUSB_GADGET_VBUS_DRAW;
	else
		power = CONFIG_USB_GADGET_VBUS_DRAW;

done:
	usb_gadget_vbus_draw(gadget, power);
	if (result >= 0 && cdev->delayed_status)