From: Daniel Baluta <daniel.baluta@intel.com>
To: jic23@kernel.org
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
daniel.baluta@intel.com, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org
Subject: [PATCH 2/3] iio: magnetometer: mmc35240: Add PM sleep support
Date: Wed, 15 Apr 2015 14:02:05 +0300 [thread overview]
Message-ID: <1429095726-10055-3-git-send-email-daniel.baluta@intel.com> (raw)
In-Reply-To: <1429095726-10055-1-git-send-email-daniel.baluta@intel.com>
We rely on regmap to save the state of the registers at suspend,
and then we do an explicit sync at resume.
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
---
drivers/iio/magnetometer/mmc35240.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/iio/magnetometer/mmc35240.c b/drivers/iio/magnetometer/mmc35240.c
index c46c1f7..4c76938 100644
--- a/drivers/iio/magnetometer/mmc35240.c
+++ b/drivers/iio/magnetometer/mmc35240.c
@@ -17,6 +17,7 @@
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/regmap.h>
+#include <linux/pm.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -454,6 +455,39 @@ static int mmc35240_remove(struct i2c_client *client)
return 0;
}
+#ifdef CONFIG_PM_SLEEP
+static int mmc35240_suspend(struct device *dev)
+{
+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct mmc35240_data *data = iio_priv(indio_dev);
+
+ regcache_cache_only(data->regmap, true);
+
+ return 0;
+}
+
+static int mmc35240_resume(struct device *dev)
+{
+ struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct mmc35240_data *data = iio_priv(indio_dev);
+ int ret;
+
+ regcache_mark_dirty(data->regmap);
+ ret = regcache_sync_region(data->regmap, MMC35240_REG_CTRL0,
+ MMC35240_REG_CTRL1);
+ if (ret < 0)
+ dev_err(dev, "Failed to restore control registers\n");
+
+ regcache_cache_only(data->regmap, false);
+
+ return 0;
+}
+#endif
+
+static const struct dev_pm_ops mmc35240_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(mmc35240_suspend, mmc35240_resume)
+};
+
static const struct i2c_device_id mmc35240_id[] = {
{"MMC35240", 0},
{}
@@ -463,6 +497,7 @@ MODULE_DEVICE_TABLE(i2c, mmc35240_id);
static struct i2c_driver mmc35240_driver = {
.driver = {
.name = MMC35240_DRV_NAME,
+ .pm = &mmc35240_pm_ops,
},
.probe = mmc35240_probe,
.remove = mmc35240_remove,
--
1.9.1
next prev parent reply other threads:[~2015-04-15 11:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-15 11:02 [PATCH 0/3] Introduce support for MMC35240 magnetic sensor Daniel Baluta
2015-04-15 11:02 ` [PATCH 1/3] iio: magnetometer: Add support for MEMSIC MMC35240 sensor Daniel Baluta
2015-04-15 11:28 ` Peter Meerwald
2015-04-15 11:46 ` Daniel Baluta
2015-04-19 13:28 ` Jonathan Cameron
2015-04-24 16:00 ` Daniel Baluta
2015-04-24 16:14 ` Daniel Baluta
2015-04-15 11:02 ` Daniel Baluta [this message]
2015-04-19 13:29 ` [PATCH 2/3] iio: magnetometer: mmc35240: Add PM sleep support Jonathan Cameron
2015-04-15 11:02 ` [PATCH 3/3] iio: magnetometer: Add ACPI support for MMC35240 Daniel Baluta
2015-04-19 13:30 ` Jonathan Cameron
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=1429095726-10055-3-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 \
/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
all inboxes | Powered by JetHome®