Re: Documentation for USB device interface for power consumption

2017-10-09 Thread Alan Stern
On Mon, 9 Oct 2017, Kai Hendry wrote:

> Hi there,
> 
> Can't see the /{proc,sys} interface documented in places I expect to be
> like https://github.com/torvalds/linux/tree/master/drivers/usb
> 
> And the mailing list search is pretty awful:
> https://marc.info/?l=linux-usb&w=2&r=1&s=power+measure&q=b
> 
> My use case is to examine the power draw from my USB port of my iPhone:
> lsusb | grep iPhone
> Bus 001 Device 009: ID 05ac:12a8 Apple, Inc. iPhone5/5C/5S/6
> 
> First problem is to identify the USB port! Currently I am `find
> /sys/devices | grep usb` & wondering how on earth it maps to "Bus 001
> Device 009: ID 05ac:12a8".

The mapping goes the other way.  Given the bus and port you can find
the device number by reading the /sys/bus/usb/devices/B-P/devnum file,
where B is the bus number and P is the port number (or path if the
device is plugged into a hub).

> Next I am hoping the see the power consumption my mA or something like
> that?

Have you tried running lsusb with the -v flag?  Or reading the 
/sys/bus/usb/devices/B-P/bMaxPower file?

> I did eventually find https://unix.stackexchange.com/a/81615/27433 but
> why isn't the a /proc like interface to this?

There is, but it's under /sys rather than /proc.

> Is there a way to see the
> negotiation somehow since my iPhone doesn't seem to like 500mA.

What negotation are you referring to?

If your iPhone doesn't like 500 mA, it doesn't have to use that much.  
The amount of current drawn by a USB device is determined almost
entirely by the device; the host won't do anything about it other than
to shut off the port if the device tries to take too much current.

In general, it's possible to see all USB traffic by using usbmon or 
wireshark.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Documentation for USB device interface for power consumption

2017-10-08 Thread Greg KH
On Mon, Oct 09, 2017 at 11:36:55AM +0800, Kai Hendry wrote:
> Hi there,
> 
> Can't see the /{proc,sys} interface documented in places I expect to be
> like https://github.com/torvalds/linux/tree/master/drivers/usb

It's documented under Documentation/ABI/ for most of the sysfs stuff,
right?

> And the mailing list search is pretty awful:
> https://marc.info/?l=linux-usb&w=2&r=1&s=power+measure&q=b

Take the search issue up with the owners of that web site :)

> My use case is to examine the power draw from my USB port of my iPhone:
> lsusb | grep iPhone
> Bus 001 Device 009: ID 05ac:12a8 Apple, Inc. iPhone5/5C/5S/6
> 
> First problem is to identify the USB port! Currently I am `find
> /sys/devices | grep usb` & wondering how on earth it maps to "Bus 001
> Device 009: ID 05ac:12a8".

We don't know, given that there is no physical mapping of logical USB
busses to physical ports by the hardware, sorry.  You can sometimes
guess as there are hints in sysfs for what port a device is connected
to.  But I don't think that will help you because:

> Next I am hoping the see the power consumption my mA or something like
> that?

You can find out what the device _says_ it will consume, but there is no
way to actually determine how much power the device is drawing without a
physical device to measure the power, sorry.  This is not something that
is possible for the OS to know as there is no hardware in the system to
measure it.

sorry,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Documentation for USB device interface for power consumption

2017-10-08 Thread Kai Hendry
Hi there,

Can't see the /{proc,sys} interface documented in places I expect to be
like https://github.com/torvalds/linux/tree/master/drivers/usb

And the mailing list search is pretty awful:
https://marc.info/?l=linux-usb&w=2&r=1&s=power+measure&q=b

My use case is to examine the power draw from my USB port of my iPhone:
lsusb | grep iPhone
Bus 001 Device 009: ID 05ac:12a8 Apple, Inc. iPhone5/5C/5S/6

First problem is to identify the USB port! Currently I am `find
/sys/devices | grep usb` & wondering how on earth it maps to "Bus 001
Device 009: ID 05ac:12a8".

Next I am hoping the see the power consumption my mA or something like
that?


I did eventually find https://unix.stackexchange.com/a/81615/27433 but
why isn't the a /proc like interface to this? Is there a way to see the
negotiation somehow since my iPhone doesn't seem to like 500mA.

Many thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html