Skip to contentSkip to conversation

usb: gadget: Increase the limit of USB_GADGET_VBUS_DRAW to 900mA

PATCH In review Prashanth K 2 participants 9 messages Jan 20, 2025 – Feb 20, 2025 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: Increase the limit of USB_GADGET_VBUS_DRAW to 900mA

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

---
 drivers/usb/gadget/Kconfig | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/usb/gadget/Kconfig +7 -4
index 76521555e3c1..904652c37385 100644
@@ -97,8 +97,8 @@ config USB_GADGET_DEBUG_FS
 	   to conserve kernel memory, say "N".
 
 config USB_GADGET_VBUS_DRAW
-	int "Maximum VBUS Power usage (2-500 mA)"
-	range 2 500
+	int "Maximum VBUS Power usage (2-900 mA)"
+	range 2 900
 	default 2
 	help
 	   Some devices need to draw power from USB when they are
@@ -107,8 +107,11 @@ config USB_GADGET_VBUS_DRAW
 	   such as an AC adapter or batteries.
 
 	   Enter the maximum power your device draws through USB, in
-	   milliAmperes.  The permitted range of values is 2 - 500 mA;
-	   0 mA would be legal, but can make some hosts misbehave.
+	   milliAmperes. The permitted range of values depends on the
+	   connection speed, for SuperSpeed and higher it's 2 - 900 mA,
+	   but connections with High-Speed or slower can draw power
+	   ranging from 2 - 500 mA; 0 mA would be legal, but can make
+	   some hosts misbehave.
 
 	   This value will be used except for system-specific gadget
 	   drivers that have more specific information.
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 38 lines
---
 drivers/usb/gadget/Kconfig | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/usb/gadget/Kconfig +7 -4
index 76521555e3c1..904652c37385 100644
@@ -97,8 +97,8 @@ config USB_GADGET_DEBUG_FS
 	   to conserve kernel memory, say "N".
 
 config USB_GADGET_VBUS_DRAW
-	int "Maximum VBUS Power usage (2-500 mA)"
-	range 2 500
+	int "Maximum VBUS Power usage (2-900 mA)"
+	range 2 900
 	default 2
 	help
 	   Some devices need to draw power from USB when they are
@@ -107,8 +107,11 @@ config USB_GADGET_VBUS_DRAW
 	   such as an AC adapter or batteries.
 
 	   Enter the maximum power your device draws through USB, in
-	   milliAmperes.  The permitted range of values is 2 - 500 mA;
-	   0 mA would be legal, but can make some hosts misbehave.
+	   milliAmperes. The permitted range of values depends on the
+	   connection speed, for SuperSpeed and higher it's 2 - 900 mA,
+	   but connections with High-Speed or slower can draw power
+	   ranging from 2 - 500 mA; 0 mA would be legal, but can make
+	   some hosts misbehave.
 
 	   This value will be used except for system-specific gadget
 	   drivers that have more specific information.
Signature · 1 line
2.25.1
#2 lore raw
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Regards,
Prashanth K

#3 lore raw
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

You are trying to improve a compile-time limitation on a quantity which isn't known until runtime. The whole idea of doing it that way is fundamentally wrong. You shouldn't try to improve it a little, you should fix the basic mistake by doing everything at runtime.

Alan Stern

#4 lore raw
Quoted 25 lines · Alan Stern
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Quoted 7 lines

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

Yes, agreed. Can we mark CONFIG_USB_GAGDGET_VBUS_DRAW as legacy and maybe also avoid configfs/composite from using it?

Quoted 7 lines

You are trying to improve a compile-time limitation on a quantity which isn't known until runtime. The whole idea of doing it that way is fundamentally wrong. You shouldn't try to improve it a little, you should fix the basic mistake by doing everything at runtime.

Alan Stern

Regards,
Prashanth K

#5 lore raw
Quoted 31 lines · Prashanth K
Quoted 28 lines · Alan Stern
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

Quoted 7 lines
Quoted 4 lines

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

Yes, agreed. Can we mark CONFIG_USB_GAGDGET_VBUS_DRAW as legacy and maybe also avoid configfs/composite from using it?

Indeed, the whole idea is to avoid using CONFIG_USB_GADGET_VBUS_DRAW in configfs and composite.

If nothing will still be using it, just remove it entirely. No need to mark it as legacy.

Alan Stern

#6 lore raw
Quoted 40 lines · Alan Stern
Quoted 31 lines · Prashanth K
Quoted 28 lines · Alan Stern
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

Quoted 7 lines
Quoted 4 lines

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

Yes, agreed. Can we mark CONFIG_USB_GAGDGET_VBUS_DRAW as legacy and maybe also avoid configfs/composite from using it?

Quoted 7 lines

Indeed, the whole idea is to avoid using CONFIG_USB_GADGET_VBUS_DRAW in configfs and composite.

If nothing will still be using it, just remove it entirely. No need to mark it as legacy.

Alan Stern

Sure, let me work on that and send a v2 (or another patch). Thanks for the feedback.

Regards,
Prashanth K

#7 lore raw
In reply to Alan Stern
Quoted 40 lines · Alan Stern
Quoted 31 lines · Prashanth K
Quoted 28 lines · Alan Stern
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

Quoted 7 lines
Quoted 4 lines

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

Yes, agreed. Can we mark CONFIG_USB_GAGDGET_VBUS_DRAW as legacy and maybe also avoid configfs/composite from using it?

Quoted 7 lines

Indeed, the whole idea is to avoid using CONFIG_USB_GADGET_VBUS_DRAW in configfs and composite.

If nothing will still be using it, just remove it entirely. No need to mark it as legacy.

Alan Stern

Hi Alan, small doubt, I see that gadget/legacy/webcam.c is a super-speed gadget which uses CONFIG_USB_GADGET_VBUS_DRAW. I'm quite not really sure if anyone uses it now, but if someone uses it, then wouldn't my patch be applicable there?

Noticed this while preparing a patch to remove dependency of VBUS_DRAW config from configfs/composite layer. Its ready, will send that after some testing.

Regards,
Prashanth K

#8 lore raw
Quoted 49 lines · Prashanth K
Quoted 46 lines · Alan Stern
Quoted 31 lines · Prashanth K
Quoted 28 lines · Alan Stern
Quoted 17 lines · Prashanth K
Quoted 7 lines · Alan Stern
Quoted 5 lines · Prashanth K

Currently CONFIG_USB_GADGET_VBUS_DRAW limits the maximum current drawn from Vbus to be up to 500mA. However USB gadget operating in SuperSpeed or higher can draw up to 900mA. Also, MaxPower in ConfigFS takes its default value from this config. Hence increase the allowed range of CONFIG_USB_GADGET_VBUS_DRAW to 900mA.

Quoted 6 lines

Is this the sort of thing that really needs to be a Kconfig option? Why not make the decision at runtime, based on the needs of the gadget or function drivers and the connection speed?

Alan Stern

Quoted 6 lines

Right, set_config() in composite.c does this in runtime based on the values of MaxPower (from configFS), VBUS_DRAW defconfig and speed. If we don't set MaxPower from configFS, this config helps to set it during compile time. In fact MaxPower in configFS takes its default value from CONFIG_USB_GADGET_VBUS_DRAW . Sent this patch because Kconfig has this limitation where it's only allowing values upto 500mA.

Why does MaxPower need to be set at compile time? Why not set it at runtime instead?

Quoted 7 lines
Quoted 4 lines

If MaxPower gets set at runtime then it can take its default value to be 500 mA or 900 mA depending on the connection speed. There will be no need for CONFIG_USB_GAGDGET_VBUS_DRAW.

Yes, agreed. Can we mark CONFIG_USB_GAGDGET_VBUS_DRAW as legacy and maybe also avoid configfs/composite from using it?

Indeed, the whole idea is to avoid using CONFIG_USB_GADGET_VBUS_DRAW in configfs and composite.

If nothing will still be using it, just remove it entirely. No need to mark it as legacy.

Quoted 6 lines
Quoted 1 line

Alan Stern

Hi Alan, small doubt, I see that gadget/legacy/webcam.c is a super-speed gadget which uses CONFIG_USB_GADGET_VBUS_DRAW. I'm quite not really sure if anyone uses it now, but if someone uses it, then wouldn't my patch be applicable there?

A quick search shows that the legacy/gmidi.c driver also uses it.

Still, if these are the only drivers that uses CONFIG_USB_GADGET_VBUS_DRAW, it means that parameter isn't really very useful.

The best solution I can think of is to make vbus_draw a module parameter in for the two drivers, with the default set to 500. That's more flexible than relying on a Kconfig parameter anyway. Of course, this means the .MaxPower field in the webcam_config_driver and midi_config structures will have to be set dynamically at runtime.

Alan Stern

Quoted 6 lines

Noticed this while preparing a patch to remove dependency of VBUS_DRAW config from configfs/composite layer. Its ready, will send that after some testing.

Regards,
Prashanth K