diff mbox series

usb: gadget: composite: Inform controller driver of self-powered

Message ID 87bd6e525dbc59cd636c3cf5a4fa1758e9da6727.1580525268.git.thinhn@synopsys.com (mailing list archive)
State Superseded
Headers show
Series usb: gadget: composite: Inform controller driver of self-powered | expand

Commit Message

Thinh Nguyen Feb. 1, 2020, 2:50 a.m. UTC
Different configuration may draw different power. Inform the controller
driver of the change so it can respond properly (e.g. GET_STATUS
request). This fixes an issue with setting MaxPower from configfs. The
composite driver doesn't check this value when setting self-powered.

Fixes: 88af8bbe4ef7 ("usb: gadget: the start of the configfs interface")
Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
 drivers/usb/gadget/composite.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Thinh Nguyen Feb. 1, 2020, 3:17 a.m. UTC | #1
++ Felipe (correct email address)

Thinh Nguyen wrote:
> Different configuration may draw different power. Inform the controller
> driver of the change so it can respond properly (e.g. GET_STATUS
> request). This fixes an issue with setting MaxPower from configfs. The
> composite driver doesn't check this value when setting self-powered.
>
> Fixes: 88af8bbe4ef7 ("usb: gadget: the start of the configfs interface")
> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
> ---
>   drivers/usb/gadget/composite.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 223f72d4d9ed..2fbeb2c19665 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -861,6 +861,11 @@ static int set_config(struct usb_composite_dev *cdev,
>   	else
>   		power = min(power, 900U);
>   done:
> +	if (power <= USB_SELF_POWER_VBUS_MAX_DRAW)
> +		usb_gadget_set_selfpowered(gadget);
> +	else
> +		usb_gadget_clear_selfpowered(gadget);
> +
>   	usb_gadget_vbus_draw(gadget, power);
>   	if (result >= 0 && cdev->delayed_status)
>   		result = USB_GADGET_DELAYED_STATUS;

The get_maintainer.pl script returned the email balbi@ti.com when it 
should be balbi@kernel.org due to git blamed fixes.

Is this a bug or intentional?

Thinh
Felipe Balbi Feb. 1, 2020, 10:36 a.m. UTC | #2
Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:

> Different configuration may draw different power. Inform the controller
> driver of the change so it can respond properly (e.g. GET_STATUS
> request). This fixes an issue with setting MaxPower from configfs. The
> composite driver doesn't check this value when setting self-powered.
>
> Fixes: 88af8bbe4ef7 ("usb: gadget: the start of the configfs interface")
> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>

we need a Cc stable here
diff mbox series

Patch

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 223f72d4d9ed..2fbeb2c19665 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -861,6 +861,11 @@  static int set_config(struct usb_composite_dev *cdev,
 	else
 		power = min(power, 900U);
 done:
+	if (power <= USB_SELF_POWER_VBUS_MAX_DRAW)
+		usb_gadget_set_selfpowered(gadget);
+	else
+		usb_gadget_clear_selfpowered(gadget);
+
 	usb_gadget_vbus_draw(gadget, power);
 	if (result >= 0 && cdev->delayed_status)
 		result = USB_GADGET_DELAYED_STATUS;