[PATCH 34/70] USB: power management for kaweth

Greg KH <[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
From: Oliver Neukum <[email protected]>

- implements suspend when the network interface is down
- fixes a typo in comments
- adds debugging output for power management
- fixes a compiler warning

Signed-off-by: Oliver Neukum <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/net/kaweth.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index fa78326..f29eed3 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -179,6 +179,7 @@ static struct usb_driver kaweth_driver = {
 	.suspend =	kaweth_suspend,
 	.resume =	kaweth_resume,
 	.id_table =     usb_klsi_table,
+	.supports_autosuspend =	1,
 };
 
 typedef __u8 eth_addr_t[6];
@@ -225,6 +226,7 @@ struct kaweth_device
 	struct delayed_work lowmem_work;
 
 	struct usb_device *dev;
+	struct usb_interface *intf;
 	struct net_device *net;
 	wait_queue_head_t term_wait;
 
@@ -662,9 +664,14 @@ static int kaweth_open(struct net_device *net)
 
 	dbg("Opening network device.");
 
+	res = usb_autopm_get_interface(kaweth->intf);
+	if (res) {
+		err("Interface cannot be resumed.");
+		return -EIO;
+	}
 	res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
 	if (res)
-		return -EIO;
+		goto err_out;
 
 	usb_fill_int_urb(
 		kaweth->irq_urb,
@@ -681,7 +688,7 @@ static int kaweth_open(struct net_device *net)
 	res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
 	if (res) {
 		usb_kill_urb(kaweth->rx_urb);
-		return -EIO;
+		goto err_out;
 	}
 	kaweth->opened = 1;
 
@@ -689,10 +696,14 @@ static int kaweth_open(struct net_device *net)
 
 	kaweth_async_set_rx_mode(kaweth);
 	return 0;
+
+err_out:
+	usb_autopm_enable(kaweth->intf);
+	return -EIO;
 }
 
 /****************************************************************
- *     kaweth_close
+ *     kaweth_kill_urbs
  ****************************************************************/
 static void kaweth_kill_urbs(struct kaweth_device *kaweth)
 {
@@ -724,6 +735,8 @@ static int kaweth_close(struct net_device *net)
 
 	kaweth->status &= ~KAWETH_STATUS_CLOSING;
 
+	usb_autopm_enable(kaweth->intf);
+
 	return 0;
 }
 
@@ -908,6 +921,7 @@ static int kaweth_suspend(struct usb_interface *intf, pm_message_t message)
 	struct kaweth_device *kaweth = usb_get_intfdata(intf);
 	unsigned long flags;
 
+	dbg("Suspending device");
 	spin_lock_irqsave(&kaweth->device_lock, flags);
 	kaweth->status |= KAWETH_STATUS_SUSPENDING;
 	spin_unlock_irqrestore(&kaweth->device_lock, flags);
@@ -924,6 +938,7 @@ static int kaweth_resume(struct usb_interface *intf)
 	struct kaweth_device *kaweth = usb_get_intfdata(intf);
 	unsigned long flags;
 
+	dbg("Resuming device");
 	spin_lock_irqsave(&kaweth->device_lock, flags);
 	kaweth->status &= ~KAWETH_STATUS_SUSPENDING;
 	spin_unlock_irqrestore(&kaweth->device_lock, flags);
@@ -1086,6 +1101,8 @@ err_fw:
 
 	dbg("Initializing net device.");
 
+	kaweth->intf = intf;
+
 	kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!kaweth->tx_urb)
 		goto err_free_netdev;
@@ -1265,7 +1282,7 @@ static int kaweth_internal_control_msg(struct usb_device *usb_dev,
 {
         struct urb *urb;
         int retv;
-        int length;
+        int length = 0; /* shut up GCC */
 
         urb = usb_alloc_urb(0, GFP_NOIO);
         if (!urb)
-- 
1.4.4.4


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.