usbnet: Support devices reporting idleness
authorOliver Neukum <oliver@neukum.org>
Thu, 11 Oct 2012 02:50:10 +0000 (02:50 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 11 Oct 2012 19:19:21 +0000 (15:19 -0400)
Some device types support a form of power management in which
the device suggests to the host that the device may be suspended
now. Support for that is best located in usbnet.

Signed-off-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/cdc_eem.c
drivers/net/usb/usbnet.c
include/linux/usb/usbnet.h

index 434d5af8e6fba0bdddcf6245945f7d3cfbb40c6c..c81e278629ff8595b6e246878e805ed51874a5c7 100644 (file)
@@ -244,8 +244,12 @@ static int eem_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
                         *  - suspend: peripheral ready to suspend
                         *  - response: suggest N millisec polling
                         *  - response complete: suggest N sec polling
+                        *
+                        * Suspend is reported and maybe heeded.
                         */
                        case 2:         /* Suspend hint */
+                               usbnet_device_suggests_idle(dev);
+                               continue;
                        case 3:         /* Response hint */
                        case 4:         /* Response complete hint */
                                continue;
index fc9f578a1e253a781b9406b1e4a43ed2de2688d1..f9819d10b1f9d41f864dc710e6799ffed9f9d5f0 100644 (file)
@@ -1588,10 +1588,27 @@ int usbnet_resume (struct usb_interface *intf)
                        tasklet_schedule (&dev->bh);
                }
        }
+
+       if (test_and_clear_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags))
+               usb_autopm_get_interface_no_resume(intf);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(usbnet_resume);
 
+/*
+ * Either a subdriver implements manage_power, then it is assumed to always
+ * be ready to be suspended or it reports the readiness to be suspended
+ * explicitly
+ */
+void usbnet_device_suggests_idle(struct usbnet *dev)
+{
+       if (!test_and_set_bit(EVENT_DEVICE_REPORT_IDLE, &dev->flags)) {
+               dev->intf->needs_remote_wakeup = 1;
+               usb_autopm_put_interface_async(dev->intf);
+       }
+}
+EXPORT_SYMBOL(usbnet_device_suggests_idle);
 
 /*-------------------------------------------------------------------------*/
 
index f87cf622317f5bc96f454b418ce1f36d3ade80b8..ddbbb7de894b4039d70003197737d5591649ad15 100644 (file)
@@ -68,6 +68,7 @@ struct usbnet {
 #              define EVENT_RX_PAUSED  5
 #              define EVENT_DEV_ASLEEP 6
 #              define EVENT_DEV_OPEN   7
+#              define EVENT_DEVICE_REPORT_IDLE 8
 };
 
 static inline struct usb_driver *driver_of(struct usb_interface *intf)
@@ -160,6 +161,7 @@ extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
 extern int usbnet_suspend(struct usb_interface *, pm_message_t);
 extern int usbnet_resume(struct usb_interface *);
 extern void usbnet_disconnect(struct usb_interface *);
+extern void usbnet_device_suggests_idle(struct usbnet *dev);
 
 
 /* Drivers that reuse some of the standard USB CDC infrastructure