On 22 December 2014 at 22:13, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > On Mon, 22 Dec 2014, Deepak Das wrote: > >> Can somebody please help me to find the test-case/use-case of >> following snippet of code in drivers/usb/core/hub.c:hub_port_connect() >> :- >> >> /* maybe switch power back on (e.g. root hub was reset) */ >> if (hub_is_port_power_switchable(hub) >> && !port_is_power_on(hub, portstatus)) >> set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); > > The use case is that for unknown reasons, the hub turned off power to > the port. I doubt that this case ever happens, though. Yes, this is really annoying. I am not able to think of any practical use-case of this code. > >> Our use case is to switch the power off on any hub port if hub >> supports per port power control but currently port is turned back ON >> due to above code snippet. > > You mustn't switch off port power; only the hub driver is allowed to do > that. If the power is switched off then the port won't work. > Yes, Correct. port will not work but that is what we needed. We need to provide userspace application control over port power for some specific requirement. Port will work again if we turn the port power back on. >> we are turning the power off by using following libusb control >> transfer function :- >> >> libusb_control_transfer( handle, >> (tU8)LIBUSB_ENDPOINT_OUT | USB_RT_PORT, >> (tU8)LIBUSB_REQUEST_CLEAR_FEATURE, >> USB_PORT_FEAT_POWER, >> PortID, >> NULL, >> 0, >> USB_TIMEOUT ); > > This is an invalid thing to do, and as you found out, it doesn't work > anyway. > > If you really insist on turning off the port power and leaving it off, > you can do this simply by unbinding the hub driver from the hub. But > then power will be turned off for _all_ the ports on that hub, and it > won't function as a hub any more. > >> In which way root hub can be reset or was reset and code flow will >> reach above statement in hub_port_connect() and turn PORT_POWER back >> ON the port? >> >> I tried to search for the use-case through git log and google but >> failed to understand. > > The Linux USB stack supports turning off port power only under a very > limited set of conditions. For example, if the port is hard-wired or > not connected at all, and if remote wakeup is not required. > Yes, we don't need remote wakeup so if hub supports per port power control then it should be turn on/off by using Set/clearPortFeature which is done by libusb control transfer function. By using libusb function we are just following "11.11 Hub Port Power Control" section of USB 2.0 spec which says it's possible by set/clearPortFeature. Please correct me If I misunderstood. > Alan Stern > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html