diff mbox

[RFC/RFT,5/5] USB: usbtouch: autosuspend for active touchscreens

Message ID 201003121544.13173.oliver@neukum.org
State New, archived
Headers show

Commit Message

Oliver Neukum March 12, 2010, 2:44 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index cc0eb7c..f89036a 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -1260,6 +1260,7 @@  static void usbtouch_irq(struct urb *urb)
 	usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
 
 exit:
+	usb_mark_last_busy(interface_to_usbdev(usbtouch->interface));
 	retval = usb_submit_urb(urb, GFP_ATOMIC);
 	if (retval)
 		err("%s - usb_submit_urb failed with result: %d",
@@ -1269,36 +1270,48 @@  exit:
 static int usbtouch_open(struct input_dev *input)
 {
 	struct usbtouch_usb *usbtouch = input_get_drvdata(input);
-	int r;
+	int rv = 0;
 
 	usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
 	
-	r = usb_autopm_get_interface(usbtouch->interface);
-	if (r < 0)
+	rv = usb_autopm_get_interface(usbtouch->interface);
+	if (rv < 0)
 		goto err_out;
 
 	if (!usbtouch->type->irq_always) {
-		if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
-		  goto err_out_revert;
+		rv = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
+		if (rv < 0)
+			goto err_out_revert;
 		usbtouch->submitted = true;
 	}
-
-	return 0;
+	usbtouch->interface->needs_remote_wakeup = 1;
 
 err_out_revert:
 	usb_autopm_put_interface(usbtouch->interface);
 err_out:
-	return -EIO;
+	return rv < 0 ? -EIO : 0;
 }
 
 static void usbtouch_close(struct input_dev *input)
 {
 	struct usbtouch_usb *usbtouch = input_get_drvdata(input);
+	int r;
 
 	usbtouch->submitted = false;
-	if (!usbtouch->type->irq_always)
+
+	/*
+	 * if the irq needs to be kept running we know remote
+	 * wakeup will be needed and as it is requested at this
+	 * time we do nothing
+	 */
+	if (!usbtouch->type->irq_always) {
 		usb_kill_urb(usbtouch->irq);
-	usb_autopm_put_interface(usbtouch->interface);
+		r = usb_autopm_get_interface(usbtouch->interface);
+		if (r == 0) {
+			usbtouch->interface->needs_remote_wakeup = 0;
+			usb_autopm_put_interface(usbtouch->interface);
+		}
+	}
 }
 
 static int usbtouch_suspend(struct usb_interface *intf, pm_message_t message)