From: Daniel Baluta <daniel.baluta@intel.com>
To: jic23@kernel.org, srinivas.pandruvada@linux.intel.com
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
daniel.baluta@intel.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] iio: pm_runtime: Introduce PM runtime helper functions
Date: Mon, 18 May 2015 19:25:27 +0300 [thread overview]
Message-ID: <1431966328-11058-2-git-send-email-daniel.baluta@intel.com> (raw)
In-Reply-To: <1431966328-11058-1-git-send-email-daniel.baluta@intel.com>
We need this in order to avoid reimplementing the same functions each time
we add PM runtime support in a driver.
Simple grep shows the following users:
* accel/mma9551.c
* accel/mmc9553.c
* accel/kxcjk1013.c
* accel/bmc150-accel.c
* gyro/bmg160.c
* imu/kmx61.c
* common/hid-sensors.
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
include/linux/iio/pm_runtime.h | 63 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 include/linux/iio/pm_runtime.h
diff --git a/include/linux/iio/pm_runtime.h b/include/linux/iio/pm_runtime.h
new file mode 100644
index 0000000..dc2bca7
--- /dev/null
+++ b/include/linux/iio/pm_runtime.h
@@ -0,0 +1,63 @@
+/*
+ * Industrial I/O runtime PM helper functions
+ *
+ * Copyright (c) 2015, Intel Corporation.
+ *
+ * This file is subject to the terms and conditions of version 2 of
+ * the GNU General Public License. See the file COPYING in the main
+ * directory of this archive for more details.
+ *
+ */
+#ifndef __IIO_PM_RUNTIME
+#define __IIO_PM_RUNTIME
+
+#include <linux/pm_runtime.h>
+
+static inline int iio_pm_runtime_setup(struct device *dev, int delay,
+ bool ignore_children)
+{
+ int ret;
+
+ ret = pm_runtime_set_active(dev);
+ if (ret)
+ return ret;
+
+ pm_suspend_ignore_children(dev, ignore_children);
+ pm_runtime_enable(dev);
+ pm_runtime_set_autosuspend_delay(dev, delay);
+ pm_runtime_use_autosuspend(dev);
+
+ return 0;
+}
+
+static inline void iio_pm_runtime_cleanup(struct device *dev)
+{
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_put_noidle(dev);
+}
+
+static inline int iio_pm_runtime_set_power(struct device *dev, bool on)
+{
+#ifdef CONFIG_PM
+ int ret;
+
+ if (on)
+ ret = pm_runtime_get_sync(dev);
+ else {
+ pm_runtime_mark_last_busy(dev);
+ ret = pm_runtime_put_autosuspend(dev);
+ }
+
+ if (ret < 0) {
+ dev_err(dev, "Failed: iio_set_power_state for %d\n", on);
+ if (on)
+ pm_runtime_put_noidle(dev);
+
+ return ret;
+ }
+#endif
+ return 0;
+}
+
+#endif /* __IIO_PM_RUNTIME */
--
1.9.1
next prev parent reply other threads:[~2015-05-18 16:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 16:25 [RFC PATCH 0/2] Introduce PM runtime helper functions Daniel Baluta
2015-05-18 16:25 ` Daniel Baluta [this message]
2015-05-18 17:34 ` [RFC PATCH 1/2] iio: pm_runtime: " Peter Meerwald
2015-05-18 18:24 ` Daniel Baluta
2015-05-18 16:25 ` [RFC PATCH 2/2] iio: accel: kxcjk1013: Use the new IIO pm runtime helpers Daniel Baluta
2015-05-18 16:54 ` [RFC PATCH 0/2] Introduce PM runtime helper functions Lars-Peter Clausen
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=1431966328-11058-2-git-send-email-daniel.baluta@intel.com \
--to=daniel.baluta@intel.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=srinivas.pandruvada@linux.intel.com \
/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).