USB / PM: Allow USB devices to remain runtime-suspended when sleeping
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Thu, 7 Jan 2016 15:46:15 +0000 (16:46 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 8 Jan 2016 00:12:06 +0000 (01:12 +0100)
Have dev_pm_ops.prepare return 1 for USB devices and ports so that USB
devices can remain runtime-suspended when the system goes to a sleep
state, if their wakeup state is correct and they have runtime PM enabled.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/usb/core/port.c
drivers/usb/core/usb.c

index 210618319f10a4110bc53191fc8a06a860992c3a..f49707d73b5acd11f95e5cc5182f025b5e003566 100644 (file)
@@ -168,12 +168,18 @@ static int usb_port_runtime_suspend(struct device *dev)
 
        return retval;
 }
+
+static int usb_port_prepare(struct device *dev)
+{
+       return 1;
+}
 #endif
 
 static const struct dev_pm_ops usb_port_pm_ops = {
 #ifdef CONFIG_PM
        .runtime_suspend =      usb_port_runtime_suspend,
        .runtime_resume =       usb_port_runtime_resume,
+       .prepare =              usb_port_prepare,
 #endif
 };
 
index f8bbd0b6d9fe44cb0077a200588c1ea054914580..cafc11902794bb1c13bf0bc7f5a68f7283ae7d81 100644 (file)
@@ -316,7 +316,13 @@ static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
 
 static int usb_dev_prepare(struct device *dev)
 {
-       return 0;               /* Implement eventually? */
+       struct usb_device *udev = to_usb_device(dev);
+
+       /* Return 0 if the current wakeup setting is wrong, otherwise 1 */
+       if (udev->do_remote_wakeup != device_may_wakeup(dev))
+               return 0;
+
+       return 1;
 }
 
 static void usb_dev_complete(struct device *dev)