linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Neukum <oliver@neukum.org>
To: Stefan Schweizer <genstef@gentoo.org>
Cc: linux-usb@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: suspend
Date: Thu, 3 Apr 2008 23:07:06 +0200	[thread overview]
Message-ID: <200804032307.06766.oliver@neukum.org> (raw)
In-Reply-To: <e79639220804030714p31cbf680y6e9cd10ed10b853d@mail.gmail.com>

Am Donnerstag, 3. April 2008 16:14:29 schrieb Stefan Schweizer:
> On Thu, Apr 3, 2008 at 12:58 PM, Oliver Neukum <oliver@neukum.org> wrote:
> >  here I have another test request. This patch on top of the earlier patch
> >  implements autosuspend for the appletouch driver. Can you try it? You
> >  also need to activate it as described in Documentation/usb/power-management.txt
> 
> this one fails to build with  several
> struct atp has no element intf
> errors.

Sorry. Here's a full patch.

	Regards
		Oliver

---

--- linux-2.6.25-rc7-vanilla/drivers/input/mouse/appletouch.c	2008-03-31 15:16:40.000000000 +0200
+++ linux-2.6.25-rc7-work/drivers/input/mouse/appletouch.c	2008-04-03 12:46:24.000000000 +0200
@@ -32,6 +32,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/usb/input.h>
 
 /* Apple has powerbooks which have the keyboard with different Product IDs */
@@ -140,6 +141,7 @@ MODULE_DEVICE_TABLE (usb, atp_table);
 struct atp {
 	char			phys[64];
 	struct usb_device *	udev;		/* usb device */
+	struct usb_interface *	intf;		/* usb interface */
 	struct urb *		urb;		/* usb request block */
 	signed char *		data;		/* transferred data */
 	struct input_dev *	input;		/* input dev */
@@ -158,6 +160,7 @@ struct atp {
 	int			datalen;	/* size of an USB urb transfer */
 	int			idlecount;      /* number of empty packets */
 	struct work_struct      work;
+	struct mutex		lock;
 };
 
 #define dbg_dump(msg, tab) \
@@ -345,6 +348,11 @@ static inline void atp_report_fingers(st
 	input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
 }
 
+static void atp_mark_busy(struct atp *dev)
+{
+	usb_mark_last_busy(dev->udev);
+}
+
 static void atp_complete(struct urb* urb)
 {
 	int x, y, x_z, y_z, x_f, y_f;
@@ -384,6 +392,9 @@ static void atp_complete(struct urb* urb
 		goto exit;
 	}
 
+	/* mark busy for autosuspend purposes */
+	atp_mark_busy(dev);
+
 	/* reorder the sensors values */
 	if (atp_is_geyser_3(dev)) {
 		memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
@@ -561,21 +572,52 @@ exit:
 static int atp_open(struct input_dev *input)
 {
 	struct atp *dev = input_get_drvdata(input);
+	int rv;
 
-	if (usb_submit_urb(dev->urb, GFP_ATOMIC))
-		return -EIO;
+	mutex_lock(&dev->lock);
+
+	rv = usb_autopm_get_interface(dev->intf);
+	if ( rv < 0)
+		goto err_out;
+
+	rv = usb_submit_urb(dev->urb, GFP_KERNEL);
+	if (rv < 0)
+		goto err_put;
 
 	dev->open = 1;
-	return 0;
+	dev->intf->needs_remote_wakeup = 1;
+
+err_put:
+	usb_autopm_put_interface(dev->intf);
+err_out:
+	mutex_unlock(&dev->lock);
+	return rv;
 }
 
 static void atp_close(struct input_dev *input)
 {
 	struct atp *dev = input_get_drvdata(input);
 
+	mutex_lock(&dev->lock);
 	usb_kill_urb(dev->urb);
 	cancel_work_sync(&dev->work);
 	dev->open = 0;
+	dev->intf->needs_remote_wakeup = 0;
+	mutex_unlock(&dev->lock);
+}
+
+static int handle_geyser(struct atp *dev)
+{
+	struct usb_device *udev = dev->udev;
+
+	if (!atp_is_fountain(dev)) {
+		/* switch to raw sensor mode */
+		if (atp_geyser_init(udev))
+			return -EIO;
+
+		printk(KERN_INFO "appletouch: Geyser mode initialized.\n");
+	}
+	return 0;
 }
 
 static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id)
@@ -612,7 +654,9 @@ static int atp_probe(struct usb_interfac
 		goto err_free_devs;
 	}
 
+	mutex_init(&dev->lock);
 	dev->udev = udev;
+	dev->intf = iface;
 	dev->input = input_dev;
 	dev->overflowwarn = 0;
 	if (atp_is_geyser_3(dev))
@@ -622,13 +666,8 @@ static int atp_probe(struct usb_interfac
 	else
 		dev->datalen = 81;
 
-	if (!atp_is_fountain(dev)) {
-		/* switch to raw sensor mode */
-		if (atp_geyser_init(udev))
-			goto err_free_devs;
-
-		printk(KERN_INFO "appletouch: Geyser mode initialized.\n");
-	}
+	if (handle_geyser(dev) < 0)
+		goto err_free_devs;
 
 	dev->urb = usb_alloc_urb(0, GFP_KERNEL);
 	if (!dev->urb)
@@ -747,19 +786,65 @@ static int atp_resume(struct usb_interfa
 {
 	struct atp *dev = usb_get_intfdata(iface);
 
-	if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
+	if (dev->open && usb_submit_urb(dev->urb, GFP_NOIO))
 		return -EIO;
 
 	return 0;
 }
 
+static int recover_dev(struct atp *dev)
+{
+	int rv;
+
+	rv = handle_geyser(dev);
+	if (rv < 0)
+		return rv;
+
+	if (dev->open && usb_submit_urb(dev->urb, GFP_NOIO))
+		return -EIO;
+
+	return 0;	
+}
+
+static int atp_pre_reset(struct usb_interface *iface)
+{
+	struct atp *dev = usb_get_intfdata(iface);
+
+	mutex_lock(&dev->lock);
+	if (dev->open)
+		usb_kill_urb(dev->urb);
+
+	return 0;
+}
+
+static int atp_post_reset(struct usb_interface *iface)
+{
+	struct atp *dev = usb_get_intfdata(iface);
+	int rv;
+
+	rv = recover_dev(dev);
+	mutex_unlock(&dev->lock);
+	return rv;
+}
+
+static int atp_reset_resume(struct usb_interface *iface)
+{
+	struct atp *dev = usb_get_intfdata(iface);
+
+	return recover_dev(dev);
+}
+
 static struct usb_driver atp_driver = {
 	.name		= "appletouch",
 	.probe		= atp_probe,
 	.disconnect	= atp_disconnect,
 	.suspend	= atp_suspend,
 	.resume		= atp_resume,
+	.reset_resume	= atp_reset_resume,
+	.pre_reset	= atp_pre_reset,
+	.post_reset	= atp_post_reset,
 	.id_table	= atp_table,
+	.supports_autosuspend = 1,
 };
 
 static int __init atp_init(void)

      reply	other threads:[~2008-04-03 21:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <dd18b0c30804012331oc548416k113e492d7dc9c189@mail.gmail.com>
     [not found] ` <200804031029.26635.oliver@neukum.org>
     [not found]   ` <e79639220804030153q46fa82c7jb79bedbe88b30df7@mail.gmail.com>
     [not found]     ` <e79639220804030153q46fa82c7jb79bedbe88b30df7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-04-03 10:31       ` suspend Oliver Neukum
     [not found]         ` <200804031231.19193.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-04-03 15:44           ` suspend Stefan Schweizer
2008-04-03 20:42             ` suspend Oliver Neukum
     [not found]               ` <200804032242.36493.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
2008-04-03 21:41                 ` suspend Alan Stern
2008-04-03 22:06                   ` suspend Stefan Schweizer
2008-04-04  8:59                     ` suspend Oliver Neukum
2008-04-04  9:20                       ` suspend Stefan Schweizer
     [not found]                         ` <e79639220804040220g560e94b4l418724ff1653780d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-04-04 11:36                           ` suspend Oliver Neukum
2008-04-04 22:40                             ` suspend Stefan Schweizer
2008-04-05  8:00                               ` suspend Oliver Neukum
2008-04-05  9:15                                 ` suspend Stefan Schweizer
     [not found]                                   ` <e79639220804050215j42829de7iab99b51e85683a53-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-04-05  9:12                                     ` suspend Oliver Neukum
2008-04-05 14:13                                 ` suspend Alan Stern
2008-04-03 10:58     ` suspend Oliver Neukum
2008-04-03 14:14       ` suspend Stefan Schweizer
2008-04-03 21:07         ` Oliver Neukum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200804032307.06766.oliver@neukum.org \
    --to=oliver@neukum.org \
    --cc=genstef@gentoo.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).