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

Commit 4be36028 authored by Mayank Rana's avatar Mayank Rana
Browse files

usb: composite: Draw 900mA on USB resume if speed is super-speed



Per USB 3.1 specification, USB device can draw upto 900mA when
enumerated in super-speed mode and bus is resumed. Fix bug that is
requesting 500mA when bus is resumed when bus is operating in
super-speed mode.

CRs-Fixed: 1063393
Change-Id: I585f4c560f0920d3cb56cce009297b5665abb42e
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent 72bf6d0b
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -27,6 +27,14 @@
#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
 * @bLength: total length of the entire descritor, always 0x12
@@ -849,7 +857,6 @@ static int set_config(struct usb_composite_dev *cdev,
	struct usb_gadget	*gadget = cdev->gadget;
	struct usb_configuration *c = NULL;
	int			result = -EINVAL;
	unsigned		power = gadget_is_otg(gadget) ? 8 : 100;
	int			tmp;

	if (number) {
@@ -938,14 +945,8 @@ static int set_config(struct usb_composite_dev *cdev,
		}
	}

	/* 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);
	usb_gadget_vbus_draw(gadget, USB_VBUS_DRAW(gadget->speed));
	if (result >= 0 && cdev->delayed_status)
		result = USB_GADGET_DELAYED_STATUS;
	return result;
@@ -2401,7 +2402,6 @@ void composite_resume(struct usb_gadget *gadget)
{
	struct usb_composite_dev	*cdev = get_gadget_data(gadget);
	struct usb_function		*f;
	u16				maxpower;
	int				ret;
	unsigned long			flags;

@@ -2434,10 +2434,7 @@ void composite_resume(struct usb_gadget *gadget)
				f->resume(f);
		}

		maxpower = cdev->config->MaxPower;

		usb_gadget_vbus_draw(gadget, maxpower ?
			maxpower : CONFIG_USB_GADGET_VBUS_DRAW);
		usb_gadget_vbus_draw(gadget, USB_VBUS_DRAW(gadget->speed));
	}

	spin_unlock_irqrestore(&cdev->lock, flags);