+ int status;
+
+ if (udev->state == USB_STATE_NOTATTACHED)
+ return -ENODEV;
+
+#ifdef CONFIG_USB_SUSPEND
+ /* selective resume of one downstream hub-to-device port */
+ if (udev->parent) {
+ if (udev->state == USB_STATE_SUSPENDED) {
+ // NOTE swsusp may bork us, device state being wrong...
+ // NOTE this fails if parent is also suspended...
+ status = hub_port_resume(hdev_to_hub(udev->parent),
+ udev->portnum, udev);
+ } else
+ status = 0;
+ } else
+#endif
+ status = finish_device_resume(udev);
+ if (status < 0)
+ dev_dbg(&udev->dev, "can't resume, status %d\n",
+ status);
+
+ /* rebind drivers that had no suspend() */
+ if (status == 0) {
+ usb_unlock_device(udev);
+ bus_rescan_devices(&usb_bus_type);
+ usb_lock_device(udev);
+ }
+ return status;
+}
+
+static int remote_wakeup(struct usb_device *udev)
+{
+ int status = 0;
+
+#ifdef CONFIG_USB_SUSPEND
+
+ /* don't repeat RESUME sequence if this device
+ * was already woken up by some other task
+ */
+ usb_lock_device(udev);
+ if (udev->state == USB_STATE_SUSPENDED) {
+ dev_dbg(&udev->dev, "RESUME (wakeup)\n");
+ /* TRSMRCY = 10 msec */
+ msleep(10);
+ status = finish_device_resume(udev);
+ }
+ usb_unlock_device(udev);
+#endif
+ return status;
+}
+
+static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
+{
+ struct usb_hub *hub = usb_get_intfdata (intf);
+ struct usb_device *hdev = hub->hdev;
+ unsigned port1;
+
+ /* fail if children aren't already suspended */
+ for (port1 = 1; port1 <= hdev->maxchild; port1++) {
+ struct usb_device *udev;
+
+ udev = hdev->children [port1-1];
+ if (udev && (udev->dev.power.power_state.event
+ == PM_EVENT_ON
+#ifdef CONFIG_USB_SUSPEND
+ || udev->state != USB_STATE_SUSPENDED
+#endif
+ )) {
+ dev_dbg(&intf->dev, "port %d nyet suspended\n", port1);
+ return -EBUSY;
+ }
+ }
+
+ /* "global suspend" of the downstream HC-to-USB interface */
+ if (!hdev->parent) {
+ struct usb_bus *bus = hdev->bus;
+ if (bus) {
+ int status = hcd_bus_suspend (bus);
+
+ if (status != 0) {
+ dev_dbg(&hdev->dev, "'global' suspend %d\n",
+ status);
+ return status;
+ }
+ } else
+ return -EOPNOTSUPP;
+ }
+
+ /* stop khubd and related activity */
+ hub_quiesce(hub);
+ return 0;
+}
+
+static int hub_resume(struct usb_interface *intf)
+{
+ struct usb_device *hdev = interface_to_usbdev(intf);
+ struct usb_hub *hub = usb_get_intfdata (intf);
+ int status;
+
+ /* "global resume" of the downstream HC-to-USB interface */
+ if (!hdev->parent) {
+ struct usb_bus *bus = hdev->bus;
+ if (bus) {
+ status = hcd_bus_resume (bus);
+ if (status) {
+ dev_dbg(&intf->dev, "'global' resume %d\n",
+ status);
+ return status;
+ }
+ } else
+ return -EOPNOTSUPP;
+ if (status == 0) {
+ /* TRSMRCY = 10 msec */
+ msleep(10);
+ }
+ }
+
+ hub_activate(hub);
+
+ /* REVISIT: this recursion probably shouldn't exist. Remove
+ * this code sometime, after retesting with different root and
+ * external hubs.
+ */
+#ifdef CONFIG_USB_SUSPEND
+ {
+ unsigned port1;
+
+ for (port1 = 1; port1 <= hdev->maxchild; port1++) {
+ struct usb_device *udev;
+ u16 portstat, portchange;
+
+ udev = hdev->children [port1-1];
+ status = hub_port_status(hub, port1, &portstat, &portchange);
+ if (status == 0) {
+ if (portchange & USB_PORT_STAT_C_SUSPEND) {
+ clear_port_feature(hdev, port1,
+ USB_PORT_FEAT_C_SUSPEND);
+ portchange &= ~USB_PORT_STAT_C_SUSPEND;
+ }
+
+ /* let khubd handle disconnects etc */
+ if (portchange)
+ continue;
+ }
+
+ if (!udev || status < 0)
+ continue;
+ usb_lock_device(udev);
+ if (portstat & USB_PORT_STAT_SUSPEND)
+ status = hub_port_resume(hub, port1, udev);
+ else {
+ status = finish_device_resume(udev);
+ if (status < 0) {
+ dev_dbg(&intf->dev, "resume port %d --> %d\n",
+ port1, status);
+ hub_port_logical_disconnect(hub, port1);
+ }
+ }
+ usb_unlock_device(udev);
+ }
+ }
+#endif