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.
> Alan Stern
> 


-- 
Best regards
Tianyu Lan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to