]> err.no Git - linux-2.6/blobdiff - drivers/usb/core/driver.c
USB: Remove usages of dev->power.power_state
[linux-2.6] / drivers / usb / core / driver.c
index 02d6db61c940a03623f46add7b10ad4c1a406d93..a3aed8d87ddc8dfc66168588b1e3f719ba965b24 100644 (file)
 #include "hcd.h"
 #include "usb.h"
 
+#define VERBOSE_DEBUG  0
+
+#if VERBOSE_DEBUG
+#define dev_vdbg       dev_dbg
+#else
+#define dev_vdbg(dev, fmt, args...)    do { } while (0)
+#endif
+
 #ifdef CONFIG_HOTPLUG
 
 /*
@@ -812,8 +820,8 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg)
        }
        status = udriver->suspend(udev, msg);
 
-done:
-       // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
+ done:
+       dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
        if (status == 0)
                udev->dev.power.power_state.event = msg.event;
        return status;
@@ -842,8 +850,8 @@ static int usb_resume_device(struct usb_device *udev)
        udriver = to_usb_device_driver(udev->dev.driver);
        status = udriver->resume(udev);
 
-done:
-       // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
+ done:
+       dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
        if (status == 0) {
                udev->autoresume_disabled = 0;
                udev->dev.power.power_state.event = PM_EVENT_ON;
@@ -881,8 +889,8 @@ static int usb_suspend_interface(struct usb_interface *intf, pm_message_t msg)
                mark_quiesced(intf);
        }
 
-done:
-       // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
+ done:
+       dev_vdbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
        return status;
 }
 
@@ -907,21 +915,37 @@ static int usb_resume_interface(struct usb_interface *intf, int reset_resume)
        }
        driver = to_usb_driver(intf->dev.driver);
 
-       if (reset_resume && driver->post_reset)
-               driver->post_reset(intf, reset_resume);
-       else if (driver->resume) {
-               status = driver->resume(intf);
-               if (status)
-                       dev_err(&intf->dev, "%s error %d\n",
-                                       "resume", status);
-       } else
-               dev_warn(&intf->dev, "no resume for driver %s?\n",
-                               driver->name);
+       if (reset_resume) {
+               if (driver->reset_resume) {
+                       status = driver->reset_resume(intf);
+                       if (status)
+                               dev_err(&intf->dev, "%s error %d\n",
+                                               "reset_resume", status);
+               } else {
+                       // status = -EOPNOTSUPP;
+                       dev_warn(&intf->dev, "no %s for driver %s?\n",
+                                       "reset_resume", driver->name);
+               }
+       } else {
+               if (driver->resume) {
+                       status = driver->resume(intf);
+                       if (status)
+                               dev_err(&intf->dev, "%s error %d\n",
+                                               "resume", status);
+               } else {
+                       // status = -EOPNOTSUPP;
+                       dev_warn(&intf->dev, "no %s for driver %s?\n",
+                                       "resume", driver->name);
+               }
+       }
 
 done:
-       // dev_dbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
+       dev_vdbg(&intf->dev, "%s: status %d\n", __FUNCTION__, status);
        if (status == 0)
                mark_active(intf);
+
+       /* FIXME: Unbind the driver and reprobe if the resume failed
+        * (not possible if auto_pm is set) */
        return status;
 }
 
@@ -958,6 +982,18 @@ static int autosuspend_check(struct usb_device *udev)
                                                "for autosuspend\n");
                                return -EOPNOTSUPP;
                        }
+
+                       /* Don't allow autosuspend if the device will need
+                        * a reset-resume and any of its interface drivers
+                        * doesn't include support.
+                        */
+                       if (udev->quirks & USB_QUIRK_RESET_RESUME) {
+                               struct usb_driver *driver;
+
+                               driver = to_usb_driver(intf->dev.driver);
+                               if (!driver->reset_resume)
+                                       return -EOPNOTSUPP;
+                       }
                }
        }
 
@@ -1083,7 +1119,7 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
        }
 
  done:
-       // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
+       dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
        return status;
 }
 
@@ -1138,7 +1174,8 @@ static int usb_resume_both(struct usb_device *udev)
                        status = usb_autoresume_device(parent);
                        if (status == 0) {
                                status = usb_resume_device(udev);
-                               if (status) {
+                               if (status || udev->state ==
+                                               USB_STATE_NOTATTACHED) {
                                        usb_autosuspend_device(parent);
 
                                        /* It's possible usb_resume_device()
@@ -1159,11 +1196,7 @@ static int usb_resume_both(struct usb_device *udev)
                        /* We can't progagate beyond the USB subsystem,
                         * so if a root hub's controller is suspended
                         * then we're stuck. */
-                       if (udev->dev.parent->power.power_state.event !=
-                                       PM_EVENT_ON)
-                               status = -EHOSTUNREACH;
-                       else
-                               status = usb_resume_device(udev);
+                       status = usb_resume_device(udev);
                }
        } else {
 
@@ -1180,7 +1213,7 @@ static int usb_resume_both(struct usb_device *udev)
        }
 
  done:
-       // dev_dbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
+       dev_vdbg(&udev->dev, "%s: status %d\n", __FUNCTION__, status);
        udev->reset_resume = 0;
        return status;
 }
@@ -1248,8 +1281,8 @@ void usb_autosuspend_device(struct usb_device *udev)
        int     status;
 
        status = usb_autopm_do_device(udev, -1);
-       // dev_dbg(&udev->dev, "%s: cnt %d\n",
-       //              __FUNCTION__, udev->pm_usage_cnt);
+       dev_vdbg(&udev->dev, "%s: cnt %d\n",
+                       __FUNCTION__, udev->pm_usage_cnt);
 }
 
 /**
@@ -1268,8 +1301,8 @@ void usb_autosuspend_device(struct usb_device *udev)
 void usb_try_autosuspend_device(struct usb_device *udev)
 {
        usb_autopm_do_device(udev, 0);
-       // dev_dbg(&udev->dev, "%s: cnt %d\n",
-       //              __FUNCTION__, udev->pm_usage_cnt);
+       dev_vdbg(&udev->dev, "%s: cnt %d\n",
+                       __FUNCTION__, udev->pm_usage_cnt);
 }
 
 /**
@@ -1296,8 +1329,8 @@ int usb_autoresume_device(struct usb_device *udev)
        int     status;
 
        status = usb_autopm_do_device(udev, 1);
-       // dev_dbg(&udev->dev, "%s: status %d cnt %d\n",
-       //              __FUNCTION__, status, udev->pm_usage_cnt);
+       dev_vdbg(&udev->dev, "%s: status %d cnt %d\n",
+                       __FUNCTION__, status, udev->pm_usage_cnt);
        return status;
 }
 
@@ -1369,8 +1402,8 @@ void usb_autopm_put_interface(struct usb_interface *intf)
        int     status;
 
        status = usb_autopm_do_interface(intf, -1);
-       // dev_dbg(&intf->dev, "%s: status %d cnt %d\n",
-       //              __FUNCTION__, status, intf->pm_usage_cnt);
+       dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
+                       __FUNCTION__, status, intf->pm_usage_cnt);
 }
 EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
 
@@ -1413,8 +1446,8 @@ int usb_autopm_get_interface(struct usb_interface *intf)
        int     status;
 
        status = usb_autopm_do_interface(intf, 1);
-       // dev_dbg(&intf->dev, "%s: status %d cnt %d\n",
-       //              __FUNCTION__, status, intf->pm_usage_cnt);
+       dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
+                       __FUNCTION__, status, intf->pm_usage_cnt);
        return status;
 }
 EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
@@ -1435,8 +1468,8 @@ int usb_autopm_set_interface(struct usb_interface *intf)
        int     status;
 
        status = usb_autopm_do_interface(intf, 0);
-       // dev_dbg(&intf->dev, "%s: status %d cnt %d\n",
-       //              __FUNCTION__, status, intf->pm_usage_cnt);
+       dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
+                       __FUNCTION__, status, intf->pm_usage_cnt);
        return status;
 }
 EXPORT_SYMBOL_GPL(usb_autopm_set_interface);