On Sat, 5 Jan 2013, Lan Tianyu wrote: > On 2013年01月04日 23:59, Alan Stern wrote: > > On Fri, 4 Jan 2013, Lan Tianyu wrote: > > > >> Some usb devices can't be resumed correctly after power off. This > >> patch is to add usb_device_allow_power_off() for device's driver to allow or > >> prohibit device to be power off the device. Call pm_runtime_get_sync(portdev) > >> to increase port's usage count and then port will not be suspended. The > >> device will not be power off. > > > > There should be two separate APIs: usb_device_allow_power_off() and > > usb_device_prevent_power_off(). If you want, they can be implemented > > as inline routines that call a single handler. > > > > Ok. > How about this? > struct device *usb_get_port_dev(struct usb_device *udev) > { > struct usb_port *port_dev; > > if (!udev->parent) > return NULL; > > port_dev = &hdev_to_hub(udev->parent)->ports[udev->portnum - 1]; > > return &port_dev->dev; > } > > static int inline usb_device_allow_power_off(struct usb_device *udev) > { > struct device *dev = usb_get_port_dev(udev); > > if(!dev) > return -ENODEV; > > return pm_runtime_put_sync(dev); > } > > > static int inline usb_device_prevent_power_off(struct usb_device *udev) > { > struct device *dev = usb_get_port_dev(udev); > > if(!dev) > return -ENODEV; > > return pm_runtime_get_sync(dev); > } > > usb_get_port_dev() locates in the driver/usb/core/port.c and > usb_device_allow/prevent_power_off() locate in the include/linux/usb.h. I was thinking more of something like this. In port.c: int usb_device_allow_prevent_power_off(struct usb_device *udev, bool allow) { ... } In include/linux/usb.h: static int inline usb_device_allow_power_off(struct usb_device *udev) { return usb_device_allow_prevent_power_off(udev, true); } static int inline usb_device_prevent_power_off(struct usb_device *udev) { return usb_device_allow_prevent_power_off(udev, false); } 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