linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Cartwright <joshc@codeaurora.org>
To: Pavel Machek <pavel@ucw.cz>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] PM: define new ASSIGN_*_PM_OPS macros based on assign_if
Date: Mon, 24 Feb 2014 11:08:26 -0600	[thread overview]
Message-ID: <1393261707-30565-3-git-send-email-joshc@codeaurora.org> (raw)
In-Reply-To: <1393261707-30565-1-git-send-email-joshc@codeaurora.org>

Similar to the SET_*_PM_OPS(), these functions are to be used in
initializers of struct dev_pm_ops, for example:

	static const struct dev_pm_ops foo_pm_ops = {
		ASSIGN_RUNTIME_PM_OPS(foo_rpm_suspend, foo_rpm_resume, NULL)
		ASSIGN_SYSTEM_SLEEP_PM_OPS(foo_suspend, foo_resume)
	};

Unlike their SET_*_PM_OPS() counter parts, it is unnecessary to wrap the
function callbacks in #ifdeffery in order to prevent 'defined but not
used' warnings when the corresponding CONFIG_PM* options are unset.

Signed-off-by: Josh Cartwright <joshc@codeaurora.org>
---
 include/linux/pm.h | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index db2be5f..3810d56 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -299,6 +299,15 @@ struct dev_pm_ops {
 	int (*runtime_idle)(struct device *dev);
 };
 
+#define assign_if_pm_sleep(fn) \
+	assign_if_enabled(CONFIG_PM_SLEEP, fn)
+
+#define assign_if_pm_runtime(fn) \
+	assign_if_enabled(CONFIG_PM_RUNTIME, fn)
+
+#define assign_if_pm(fn) \
+	assign_if_enabled(CONFIG_PM, fn)
+
 #ifdef CONFIG_PM_SLEEP
 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
 	.suspend = suspend_fn, \
@@ -342,6 +351,36 @@ struct dev_pm_ops {
 #endif
 
 /*
+ * The ASSIGN_* variations of the above make wrapping the associated callback
+ * functions in preprocessor defines unnecessary.
+ */
+#define ASSIGN_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
+	.suspend = assign_if_pm_sleep(suspend_fn), \
+	.resume = assign_if_pm_sleep(resume_fn), \
+	.freeze = assign_if_pm_sleep(suspend_fn), \
+	.thaw = assign_if_pm_sleep(resume_fn), \
+	.poweroff = assign_if_pm_sleep(suspend_fn), \
+	.restore = assign_if_pm_sleep(resume_fn),
+
+#define ASSIGN_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
+	.suspend_late = assign_if_pm_sleep(suspend_fn), \
+	.resume_early = assign_if_pm_sleep(resume_fn), \
+	.freeze_late = assign_if_pm_sleep(suspend_fn), \
+	.thaw_early = assign_if_pm_sleep(resume_fn), \
+	.poweroff_late = assign_if_pm_sleep(suspend_fn), \
+	.restore_early = assign_if_pm_sleep(resume_fn),
+
+#define ASSIGN_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
+	.runtime_suspend = assign_if_pm_runtime(suspend_fn), \
+	.runtime_resume = assign_if_pm_runtime(resume_fn), \
+	.runtime_idle = assign_if_pm_runtime(idle_fn),
+
+#define ASSIGN_PM_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
+	.runtime_suspend = assign_if_pm(suspend_fn), \
+	.runtime_resume = assign_if_pm(resume_fn), \
+	.runtime_idle = assign_if_pm(idle_fn),
+
+/*
  * Use this if you want to use the same suspend and resume callbacks for suspend
  * to RAM and hibernation.
  */
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

  parent reply	other threads:[~2014-02-24 17:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-24 17:08 [PATCH 0/3] introduce assign_if() macros in attempt to reduce ifdeffery Josh Cartwright
2014-02-24 17:08 ` [PATCH 1/3] typecheck: introduce assign_if() and assign_if_enabled() Josh Cartwright
2014-02-27 19:00   ` Greg Kroah-Hartman
2014-02-27 23:48     ` Josh Cartwright
2014-02-24 17:08 ` Josh Cartwright [this message]
2014-02-27 19:02   ` [PATCH 2/3] PM: define new ASSIGN_*_PM_OPS macros based on assign_if Greg Kroah-Hartman
2014-03-01 11:06     ` Pavel Machek
2014-03-01 16:02       ` Greg Kroah-Hartman
2014-03-01 16:26         ` Pavel Machek
2014-02-24 17:08 ` [PATCH 3/3] usb: phy: msm: use ASSIGN_*_PM_OPS variants Josh Cartwright
     [not found]   ` <1393261707-30565-4-git-send-email-joshc-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-02-25 18:33     ` Felipe Balbi
2014-02-27 19:03       ` Greg Kroah-Hartman
2014-02-27 23:41         ` David Cohen
2014-02-27 23:44           ` Greg Kroah-Hartman
     [not found]             ` <20140227234425.GA32426-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2014-02-27 23:52               ` David Cohen
2014-02-28  8:48             ` Ulf Hansson
2014-02-28 16:52               ` Greg Kroah-Hartman
2014-03-01 11:24                 ` Ulf Hansson

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=1393261707-30565-3-git-send-email-joshc@codeaurora.org \
    --to=joshc@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    /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).