All of lore.kernel.org
 help / color / mirror / Atom feed
* [rft]power management for usbtouch
@ 2008-06-26 13:57 Oliver Neukum
  2008-06-26 14:45 ` Ville Syrjälä
  0 siblings, 1 reply; 33+ messages in thread
From: Oliver Neukum @ 2008-06-26 13:57 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: daniel.ritz-OI3hZJvNYWs, Dmitry Torokhov, Jiri Kosina,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-input-u79uwXL29TY76Z2rM5mHXA

Hi,

this is power management for usbtouch. Could somebody test it?

	Regards
		Oliver

---

--- linux-2.6.26-sierra/drivers/input/touchscreen/usbtouchscreen.c.alt2	2008-06-26 15:23:38.000000000 +0200
+++ linux-2.6.26-sierra/drivers/input/touchscreen/usbtouchscreen.c	2008-06-26 15:48:44.000000000 +0200
@@ -89,13 +89,17 @@ struct usbtouch_usb {
 	int buf_len;
 	struct urb *irq;
 	struct usb_device *udev;
+	struct usb_interface *intf;
 	struct input_dev *input;
 	struct usbtouch_device_info *type;
+	struct mutex lock;
 	char name[128];
 	char phys[64];
 
 	int x, y;
 	int touch, press;
+
+	char open:1;
 };
 
 
@@ -820,13 +824,23 @@ exit:
 static int usbtouch_open(struct input_dev *input)
 {
 	struct usbtouch_usb *usbtouch = input_get_drvdata(input);
+	int rv;
 
+	rv = usb_autopm_get_interface(usbtouch->intf);
+	if (rv < 0)
+		goto bail;
+	mutex_lock(&usbtouch->lock);
 	usbtouch->irq->dev = usbtouch->udev;
 
-	if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
-		return -EIO;
-
-	return 0;
+	if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) {
+		rv = -EIO;
+		usb_autopm_put_interface(usbtouch->intf);
+	} else {
+		usbtouch->open = 1;
+	}
+	mutex_unlock(&usbtouch->lock);
+bail:
+	return rv;
 }
 
 static void usbtouch_close(struct input_dev *input)
@@ -834,6 +848,10 @@ static void usbtouch_close(struct input_
 	struct usbtouch_usb *usbtouch = input_get_drvdata(input);
 
 	usb_kill_urb(usbtouch->irq);
+	mutex_lock(&usbtouch->lock);
+	usbtouch->open = 0;
+	mutex_unlock(&usbtouch->lock);
+	usb_autopm_put_interface(usbtouch->intf);
 }
 
 
@@ -889,6 +907,8 @@ static int usbtouch_probe(struct usb_int
 
 	usbtouch->udev = udev;
 	usbtouch->input = input_dev;
+	mutex_init(&usbtouch->lock);
+	usbtouch->intf = intf;
 
 	if (udev->manufacturer)
 		strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
@@ -973,20 +993,76 @@ static void usbtouch_disconnect(struct u
 
 	dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__);
 	usb_set_intfdata(intf, NULL);
-	input_unregister_device(usbtouch->input);
 	usb_kill_urb(usbtouch->irq);
+	input_unregister_device(usbtouch->input);
 	usb_free_urb(usbtouch->irq);
 	usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
 	kfree(usbtouch);
 }
 
+static int usbtouch_suspend(struct usb_interface *intf, pm_message_t message)
+{
+	struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+
+	dbg("%s - called", __FUNCTION__);
+
+	mutex_lock(&usbtouch->lock);
+	usb_kill_urb(usbtouch->irq);
+	mutex_unlock(&usbtouch->lock);
+	return 0;
+}
+
+static int usbtouch_resume(struct usb_interface *intf)
+{
+	struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+	int rv = 0;
+
+	dbg("%s - called", __FUNCTION__);
+
+	mutex_lock(&usbtouch->lock);
+	if (usbtouch->open)
+		rv = usb_submit_urb(usbtouch->irq, GFP_NOIO);
+	mutex_unlock(&usbtouch->lock);
+	return rv;
+}
+
+static int usbtouch_pre_reset(struct usb_interface *intf)
+{
+	struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+
+	dbg("%s - called", __FUNCTION__);
+
+	mutex_lock(&usbtouch->lock);
+	usb_kill_urb(usbtouch->irq);
+	return 0;
+}
+
+static int usbtouch_post_reset(struct usb_interface *intf)
+{
+	struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
+	int rv = 0;
+
+	dbg("%s - called", __FUNCTION__);
+
+	if (usbtouch->open)
+		rv = usb_submit_urb(usbtouch->irq, GFP_NOIO);
+	mutex_unlock(&usbtouch->lock);
+	return rv;
+}
+
 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
 
 static struct usb_driver usbtouch_driver = {
 	.name		= "usbtouchscreen",
 	.probe		= usbtouch_probe,
 	.disconnect	= usbtouch_disconnect,
+	.suspend	= usbtouch_suspend,
+	.resume		= usbtouch_resume,
+	.reset_resume	= usbtouch_resume,
+	.pre_reset	= usbtouch_pre_reset,
+	.post_reset	= usbtouch_post_reset,
 	.id_table	= usbtouch_devices,
+	.supports_autosuspend = 1,
 };
 
 static int __init usbtouch_init(void)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2008-07-01 19:03 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-26 13:57 [rft]power management for usbtouch Oliver Neukum
2008-06-26 14:45 ` Ville Syrjälä
     [not found]   ` <20080626144545.GF22310-ORSVBvAovxo@public.gmane.org>
2008-06-26 14:56     ` Oliver Neukum
     [not found]       ` <200806261656.06457.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-06-27  8:50         ` Oliver Neukum
2008-06-27 13:17           ` Ville Syrjälä
2008-06-27 16:10           ` Ville Syrjälä
     [not found]             ` <20080627161036.GE19430-ORSVBvAovxo@public.gmane.org>
2008-06-27 19:07               ` Oliver Neukum
2008-06-27 20:20                 ` Ville Syrjälä
     [not found]                   ` <20080627202027.GG19430-ORSVBvAovxo@public.gmane.org>
2008-06-27 20:41                     ` Oliver Neukum
     [not found]                       ` <200806272241.22513.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-06-27 20:51                         ` Ville Syrjälä
     [not found]                           ` <20080627205147.GI19430-ORSVBvAovxo@public.gmane.org>
2008-06-27 20:57                             ` Oliver Neukum
2008-06-27 21:28                               ` Ville Syrjälä
2008-06-28 10:52                                 ` Oliver Neukum
2008-06-28 11:22                                   ` Ville Syrjälä
     [not found]                                     ` <20080628112258.GK19430-ORSVBvAovxo@public.gmane.org>
2008-06-28 12:53                                       ` Oliver Neukum
2008-06-28 16:33                                         ` Alan Stern
2008-06-28 22:47                                           ` Oliver Neukum
     [not found]                                             ` <200806290047.56736.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-06-30 15:29                                               ` Dmitry Torokhov
2008-06-30 15:47                                                 ` Alan Stern
2008-06-30 16:02                                                   ` Dmitry Torokhov
     [not found]                                                     ` <20080630115953.ZZRA012-NG0XCrj25/nJrYCpivWRnl5pS2h4L8biXqFh9Ls21Oc@public.gmane.org>
2008-06-30 16:16                                                       ` Alan Stern
2008-06-30 16:30                                                         ` Dmitry Torokhov
2008-06-30 16:58                                                           ` Alan Stern
2008-06-30 22:46                                                     ` Oliver Neukum
     [not found]                                                       ` <200807010046.34219.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-07-01  7:59                                                         ` Jiri Kosina
2008-07-01  9:08                                                           ` Oliver Neukum
2008-07-01 12:56                                                             ` Dmitry Torokhov
2008-07-01 15:00                                                               ` Alan Stern
     [not found]                                                                 ` <Pine.LNX.4.44L0.0807011058340.2780-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2008-07-01 16:02                                                                   ` Dmitry Torokhov
     [not found]                                                               ` <20080701085504.ZZRA012-NG0XCrj25/nJrYCpivWRnl5pS2h4L8biXqFh9Ls21Oc@public.gmane.org>
2008-07-01 16:57                                                                 ` Oliver Neukum
     [not found]                                                                   ` <200807011857.02259.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-07-01 17:39                                                                     ` Ville Syrjälä
2008-07-01 19:03                                                                       ` Alan Stern
2008-06-27 13:17       ` Ville Syrjälä

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.