On Tue, 26 Jun 2007, Jüri Reitel wrote: > Looked into drivers/usb/core/devio.c functions > usbdev_ioctl > proc_ioctl_default > proc_ioctl > USBDEVFS_DISCONNECT branch calls usb_driver_release_interface > > As i can understand i should obtain list of all interfaces registered to > the port that i want to turn of the power and then call usbdev ioctl
Don't do this. Just call usb_disconnect(). > drivers/usb/core/hub.c has function void usb_disconnect(struct > usb_device **pdev) > I exported usb_disconnect function and use it in my own driver where i > get struct usb_device * hub, because i know bus topology > static int set_usb_port_power_state(struct usb_device *hub, int port, > int new_state) > { > int ret; > if (new_state) { > ret = set_usb_hub_port_feature(hub, port, USB_PORT_FEAT_POWER); > } else { > //notify also children device drivers > if (port > 0 && port <= USB_MAXCHILDREN && hub->children[port - > 1]) { If you're going to test to see if port is a valid number, you should do the test at the start of the routine -- before checking new_state. > usb_disconnect(&hub->children[port - 1]); > } > ret = clear_usb_hub_port_feature(hub, port, USB_PORT_FEAT_POWER); > } > return ret; > } > > hub is obtained with usb_get_dev and later put with usb_put_dev > > First tests have been successful, with usb to usb hub and with root hub > althoug i had to change some files in usb/host/ > The most hardest part to me is to understand the needed locks before > calling kernel functions Your routine needs to call usb_lock_device(hub) at the start and usb_unlock_device(hub) at the end. And you also need to clear the USB_PORT_FEAT_C_CONNECT and USB_PORT_FEAT_C_ENABLE features after turning off the port power. In general doing this with root hubs simply will not work. The USB controllers used on most PCs never turn off power to their ports. Alan Stern ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel