linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	linux-serial@vger.kernel.org, Pavel Machek <pavel@ucw.cz>,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH 1/2] power: Add function to init wakeup capability without enabling
Date: Wed, 18 Jan 2012 15:07:06 -0800	[thread overview]
Message-ID: <1326928027-20610-1-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1326826563-32215-3-git-send-email-sjg@chromium.org>

device_init_wakeup() offers two options:

1. Wakeup capable and wakeup enabled
2  Not wakeup capable and not wakeup enabled

serial_core wants a third option:

3. Wakeup capable but not wakeup enabled (yet)

Add a new init routine which takes a flag indicating which of the three
options is required. This avoids creating and then destroying the wakeup
source to no purpose, and a sometimes large rcu_synchronise() delay.

Q: What is a good name for the new function?

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 drivers/base/power/wakeup.c |   26 ++++++++++++++++++++++----
 include/linux/pm_wakeup.h   |   22 +++++++++++++++++++---
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index caf995f..ae3b3c5 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -273,7 +273,7 @@ EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
 /**
  * device_init_wakeup - Device wakeup initialization.
  * @dev: Device to handle.
- * @enable: Whether or not to enable @dev as a wakeup device.
+ * @flags: flags PM_WAKEUP_...
  *
  * By default, most devices should leave wakeup disabled.  The exceptions are
  * devices that everyone expects to be wakeup sources: keyboards, power buttons,
@@ -281,19 +281,37 @@ EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
  * own wakeup requests but merely forward requests from one bus to another
  * (like PCI bridges) should have wakeup enabled by default.
  */
-int device_init_wakeup(struct device *dev, bool enable)
+int device_init_wakeup_flag(struct device *dev, int flags)
 {
 	int ret = 0;
 
-	if (enable) {
+	if (flags & PM_WAKEUP_CAP) {
 		device_set_wakeup_capable(dev, true);
-		ret = device_wakeup_enable(dev);
+		if (flags & PM_WAKEUP_EN)
+			ret = device_wakeup_enable(dev);
 	} else {
+		WARN_ON(flags & PM_WAKEUP_EN);
 		device_set_wakeup_capable(dev, false);
 	}
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(device_init_wakeup_flag);
+
+/**
+ * device_init_wakeup - Device wakeup initialization.
+ * @dev: Device to handle.
+ * @enable: Whether or not to enable @dev as a wakeup device.
+ *
+ * By default, most devices should leave wakeup disabled.  The exceptions are
+ * devices that everyone expects to be wakeup sources: keyboards, power buttons,
+ * possibly network interfaces, etc.
+ */
+int device_init_wakeup(struct device *dev, bool enable)
+{
+	return device_init_wakeup_flag(dev, enable ? PM_WAKEUP_CAP_EN :
+				       PM_WAKEUP_NONE);
+}
 EXPORT_SYMBOL_GPL(device_init_wakeup);
 
 /**
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index a32da96..3035875 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -56,6 +56,14 @@ struct wakeup_source {
 	unsigned int		active:1;
 };
 
+/* Flags for device_init_wakeup_flag() */
+enum {
+	PM_WAKEUP_NONE,		/* Not wakeup capable */
+	PM_WAKEUP_CAP,		/* Wakeup capable but not enabled */
+	PM_WAKEUP_EN,		/* Don't use */
+	PM_WAKEUP_CAP_EN,	/* Wakeup capable and enabled */
+};
+
 #ifdef CONFIG_PM_SLEEP
 
 /*
@@ -83,6 +91,7 @@ extern int device_wakeup_enable(struct device *dev);
 extern int device_wakeup_disable(struct device *dev);
 extern void device_set_wakeup_capable(struct device *dev, bool capable);
 extern int device_init_wakeup(struct device *dev, bool val);
+extern int device_init_wakeup_flag(struct device *dev, int flags);
 extern int device_set_wakeup_enable(struct device *dev, bool enable);
 extern void __pm_stay_awake(struct wakeup_source *ws);
 extern void pm_stay_awake(struct device *dev);
@@ -139,13 +148,20 @@ static inline int device_set_wakeup_enable(struct device *dev, bool enable)
 	return 0;
 }
 
-static inline int device_init_wakeup(struct device *dev, bool val)
+static inline device_init_wakeup_flag(struct device *dev, int flags)
 {
-	device_set_wakeup_capable(dev, val);
-	device_set_wakeup_enable(dev, val);
+	device_set_wakeup_capable(dev, flags & PM_WAKEUP_CAP);
+	if (flags & PM_WAKEUP_EN)
+		device_set_wakeup_enable(dev, true);
 	return 0;
 }
 
+static inline int device_init_wakeup(struct device *dev, bool enable)
+{
+	return device_init_wakeup_flag(enable ? PM_WAKEUP_CAP_EN :
+				       PM_WAKEUP_NONE);
+}
+
 static inline bool device_may_wakeup(struct device *dev)
 {
 	return dev->power.can_wakeup && dev->power.should_wakeup;
-- 
1.7.7.3


  parent reply	other threads:[~2012-01-18 23:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-17 18:56 [PATCH 1/3] serial: 8250: Remove trailing space in 8250 driver Simon Glass
2012-01-17 18:56 ` [PATCH 2/3] serial: Make wakeup_capable a flag to reduce boot time Simon Glass
2012-01-17 20:09   ` Alan Cox
2012-01-17 18:56 ` [PATCH 3/3] serial: 8250: Add a wakeup_capable module param Simon Glass
2012-01-17 20:10   ` Alan Cox
2012-01-18  4:17     ` Paul E. McKenney
2012-01-18 21:08       ` Simon Glass
2012-01-18 21:42         ` Paul E. McKenney
2012-01-18 22:15           ` Simon Glass
2012-01-18 22:43             ` Paul E. McKenney
2012-01-18 22:51               ` Simon Glass
2012-01-19  0:02               ` Rafael J. Wysocki
2012-01-19  1:37                 ` Paul E. McKenney
2012-01-19  2:35                   ` Simon Glass
2012-01-19 19:13                     ` Paul E. McKenney
2012-01-20  0:03                   ` Rafael J. Wysocki
2012-01-20  6:12                     ` Paul E. McKenney
2012-01-20 23:49                       ` Rafael J. Wysocki
2012-01-23 16:45                         ` Paul E. McKenney
2012-01-23 21:04                           ` Rafael J. Wysocki
2012-01-18 22:12         ` Alan Cox
2012-01-18 22:19           ` Simon Glass
2012-01-19  0:08         ` Rafael J. Wysocki
2012-01-19  0:58           ` Simon Glass
2012-01-18 23:07   ` Simon Glass [this message]
2012-01-18 23:07     ` [PATCH 2/2] serial: Use device_init_wakeup_flag() to make device wakeup-capable Simon Glass
2012-01-19  0:10     ` [PATCH 1/2] power: Add function to init wakeup capability without enabling Rafael J. Wysocki

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=1326928027-20610-1-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@sisk.pl \
    /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).