To: gre...@linuxfoundation.org,
    sarah.a.sh...@linux.intel.com,
    st...@rowland.harvard.edu,
    r...@sisk.pl,
    oneu...@suse.de
Cc: linux-usb@vger.kernel.org,
    tianyu....@intel.com,
    sebastien.duf...@intel.com

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.

Signed-off-by: Lan Tianyu <tianyu....@intel.com>
---
 drivers/usb/core/hub.c |   28 ++++++++++++++++++++++++++++
 include/linux/usb.h    |    1 +
 2 files changed, 29 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index acefb67..e53e371 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -135,6 +135,34 @@ struct usb_hub *hdev_to_hub(struct usb_device *hdev)
        return usb_get_intfdata(hdev->actconfig->interface[0]);
 }
 
+/**
+ * usb_device_allow_power_off - Allow or prohibit power off device.
+ * @udev: target usb device
+ * @set: choice of allow or prohibit
+ *
+ * Call pm_runtime_get/put_sync(portdev) to allow or prohibit target
+ * usb device to be power off in the kernel. The operations of setting
+ * true and false should be couple. The default status is allowed.
+ */
+int usb_device_allow_power_off(struct usb_device *udev, bool set)
+{
+       struct usb_port *port_dev;
+
+       if (!udev->parent)
+               return -EINVAL;
+
+       port_dev =
+               hdev_to_hub(udev->parent)->ports[udev->portnum - 1];
+
+       if (set)
+               pm_runtime_put_sync(&port_dev->dev);
+       else
+               pm_runtime_get_sync(&port_dev->dev);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(usb_device_allow_power_off);
+
 static int usb_device_supports_lpm(struct usb_device *udev)
 {
        /* USB 2.1 (and greater) devices indicate LPM support through
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 689b14b..e0b5f54 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -581,6 +581,7 @@ extern struct usb_device *usb_get_dev(struct usb_device 
*dev);
 extern void usb_put_dev(struct usb_device *dev);
 extern struct usb_device *usb_hub_find_child(struct usb_device *hdev,
        int port1);
+extern int usb_device_allow_power_off(struct usb_device *udev, bool set);
 
 /**
  * usb_hub_for_each_child - iterate over all child devices on the hub
-- 
1.7.9.5

--
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

Reply via email to