All of lore.kernel.org
 help / color / mirror / Atom feed
* Enumerating USB devices in the Bootloader
@ 2020-02-10 15:02 Martin Townsend
  2020-02-10 15:12 ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Townsend @ 2020-02-10 15:02 UTC (permalink / raw)
  To: linux-usb

Hi,

We are using the USB mass storage gadget driver in Linux and
everything is working fairly well but sometimes we are finding that we
are exceeding the 100mA limit (which I think is the default the host
will provide) before Linux has had a change to enumerate the USB
device at which point we ask for 500mA.  We have tried to reduce the
power by ensuring all clocks are turned off, devices not used disabled
etc but can't seem to satisfy the 100mA limit.  We were thinking that
maybe we could enumerate the USB device during U-Boot at which point
we know we are under the 100mA limit.  Does anyone know a reason why
this would not work? would at some point from U-Boot enumerating a new
bMaxPower would the connection be reset and drop back to 100mA during
the kernel startup? Are there any considerations that we would need to
take care of in the kernel for this to work?

Many Thanks,
Martin.

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

* Re: Enumerating USB devices in the Bootloader
  2020-02-10 15:02 Enumerating USB devices in the Bootloader Martin Townsend
@ 2020-02-10 15:12 ` Alan Stern
  2020-02-11 17:25   ` Martin Townsend
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2020-02-10 15:12 UTC (permalink / raw)
  To: Martin Townsend; +Cc: linux-usb

On Mon, 10 Feb 2020, Martin Townsend wrote:

> Hi,
> 
> We are using the USB mass storage gadget driver in Linux and
> everything is working fairly well but sometimes we are finding that we
> are exceeding the 100mA limit (which I think is the default the host
> will provide) before Linux has had a change to enumerate the USB
> device at which point we ask for 500mA.  We have tried to reduce the
> power by ensuring all clocks are turned off, devices not used disabled
> etc but can't seem to satisfy the 100mA limit.  We were thinking that
> maybe we could enumerate the USB device during U-Boot at which point
> we know we are under the 100mA limit.  Does anyone know a reason why
> this would not work?

It won't work because U-Boot isn't the kernel.  When the kernel takes 
over the USB controller, it will force the host to re-enumerate the 
gadget -- and you will be right back where you started.

The only way to make this work would be to prevent U-Boot from ever 
actually booting the Linux kernel.  This probably isn't the way you 
want your device to behave, though.

> would at some point from U-Boot enumerating a new
> bMaxPower would the connection be reset and drop back to 100mA during
> the kernel startup? Are there any considerations that we would need to
> take care of in the kernel for this to work?

If you can't satisfy the 100-mA current limit then you should make your
device be self-powered instead of relying on power delivered over the
USB bus.

Be aware also that bus-powered USB-2 hubs can't deliver 500 mA to their
downstream ports.  They are always limited to 100 mA or less.  If your
gadget was plugged into one of them, it wouldn't be able to work at 
all.

Alan Stern


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

* Re: Enumerating USB devices in the Bootloader
  2020-02-10 15:12 ` Alan Stern
@ 2020-02-11 17:25   ` Martin Townsend
  2020-02-11 19:02     ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Townsend @ 2020-02-11 17:25 UTC (permalink / raw)
  To: Alan Stern; +Cc: linux-usb

On Mon, Feb 10, 2020 at 3:12 PM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Mon, 10 Feb 2020, Martin Townsend wrote:
>
> > Hi,
> >
> > We are using the USB mass storage gadget driver in Linux and
> > everything is working fairly well but sometimes we are finding that we
> > are exceeding the 100mA limit (which I think is the default the host
> > will provide) before Linux has had a change to enumerate the USB
> > device at which point we ask for 500mA.  We have tried to reduce the
> > power by ensuring all clocks are turned off, devices not used disabled
> > etc but can't seem to satisfy the 100mA limit.  We were thinking that
> > maybe we could enumerate the USB device during U-Boot at which point
> > we know we are under the 100mA limit.  Does anyone know a reason why
> > this would not work?
>
> It won't work because U-Boot isn't the kernel.  When the kernel takes
> over the USB controller, it will force the host to re-enumerate the
> gadget -- and you will be right back where you started.
>
> The only way to make this work would be to prevent U-Boot from ever
> actually booting the Linux kernel.  This probably isn't the way you
> want your device to behave, though.
>
> > would at some point from U-Boot enumerating a new
> > bMaxPower would the connection be reset and drop back to 100mA during
> > the kernel startup? Are there any considerations that we would need to
> > take care of in the kernel for this to work?
>
> If you can't satisfy the 100-mA current limit then you should make your
> device be self-powered instead of relying on power delivered over the
> USB bus.
>
> Be aware also that bus-powered USB-2 hubs can't deliver 500 mA to their
> downstream ports.  They are always limited to 100 mA or less.  If your
> gadget was plugged into one of them, it wouldn't be able to work at
> all.
>
> Alan Stern
>

Alan,
Thank you for the swift response.  On the first point, if we modify
the kernel to re-enumerate the same bMaxPower of 500mA would this
still be a problem? ie is there a period when the kernel takes over
the USB controller that the Host side would go back to 100mA after
U-Boot negotiates the 500mA?  The last point you make is a very good
one and something I hadn't thought of. If we can overcome the first
hurdle I think we would be happy for it to be a requirement for the
device to be plugged directly into a PC.

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

* Re: Enumerating USB devices in the Bootloader
  2020-02-11 17:25   ` Martin Townsend
@ 2020-02-11 19:02     ` Alan Stern
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Stern @ 2020-02-11 19:02 UTC (permalink / raw)
  To: Martin Townsend; +Cc: linux-usb

On Tue, 11 Feb 2020, Martin Townsend wrote:

> On Mon, Feb 10, 2020 at 3:12 PM Alan Stern <stern@rowland.harvard.edu> wrote:
> >
> > On Mon, 10 Feb 2020, Martin Townsend wrote:
> >
> > > Hi,
> > >
> > > We are using the USB mass storage gadget driver in Linux and
> > > everything is working fairly well but sometimes we are finding that we
> > > are exceeding the 100mA limit (which I think is the default the host
> > > will provide) before Linux has had a change to enumerate the USB
> > > device at which point we ask for 500mA.  We have tried to reduce the
> > > power by ensuring all clocks are turned off, devices not used disabled
> > > etc but can't seem to satisfy the 100mA limit.  We were thinking that
> > > maybe we could enumerate the USB device during U-Boot at which point
> > > we know we are under the 100mA limit.  Does anyone know a reason why
> > > this would not work?
> >
> > It won't work because U-Boot isn't the kernel.  When the kernel takes
> > over the USB controller, it will force the host to re-enumerate the
> > gadget -- and you will be right back where you started.
> >
> > The only way to make this work would be to prevent U-Boot from ever
> > actually booting the Linux kernel.  This probably isn't the way you
> > want your device to behave, though.
> >
> > > would at some point from U-Boot enumerating a new
> > > bMaxPower would the connection be reset and drop back to 100mA during
> > > the kernel startup? Are there any considerations that we would need to
> > > take care of in the kernel for this to work?
> >
> > If you can't satisfy the 100-mA current limit then you should make your
> > device be self-powered instead of relying on power delivered over the
> > USB bus.
> >
> > Be aware also that bus-powered USB-2 hubs can't deliver 500 mA to their
> > downstream ports.  They are always limited to 100 mA or less.  If your
> > gadget was plugged into one of them, it wouldn't be able to work at
> > all.
> >
> > Alan Stern
> >
> 
> Alan,
> Thank you for the swift response.  On the first point, if we modify
> the kernel to re-enumerate the same bMaxPower of 500mA would this
> still be a problem? ie is there a period when the kernel takes over
> the USB controller that the Host side would go back to 100mA after
> U-Boot negotiates the 500mA?

Yes, there is.  Remember, the kernel knows nothing of what U-Boot has 
done.  It has to start fresh.

>  The last point you make is a very good
> one and something I hadn't thought of. If we can overcome the first
> hurdle I think we would be happy for it to be a requirement for the
> device to be plugged directly into a PC.

Or into a powered hub.

Alan Stern


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

end of thread, other threads:[~2020-02-11 19:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 15:02 Enumerating USB devices in the Bootloader Martin Townsend
2020-02-10 15:12 ` Alan Stern
2020-02-11 17:25   ` Martin Townsend
2020-02-11 19:02     ` Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.