linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: composite: Inform controller driver of self-powered
@ 2020-02-01  2:50 Thinh Nguyen
  2020-02-01  3:17 ` Thinh Nguyen
  2020-02-01 10:36 ` Felipe Balbi
  0 siblings, 2 replies; 3+ messages in thread
From: Thinh Nguyen @ 2020-02-01  2:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Felipe Balbi, Sebastian Andrzej Siewior
  Cc: Thinh Nguyen, linux-usb

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;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-01 10:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-01  2:50 [PATCH] usb: gadget: composite: Inform controller driver of self-powered Thinh Nguyen
2020-02-01  3:17 ` Thinh Nguyen
2020-02-01 10:36 ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).