All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tiberiu Breana <tiberiu.a.breana@intel.com>
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 2/3] iio: light: Add Power Management for STK3310
Date: Tue, 14 Apr 2015 12:32:41 +0300	[thread overview]
Message-ID: <1429003962-13922-3-git-send-email-tiberiu.a.breana@intel.com> (raw)
In-Reply-To: <1429003962-13922-1-git-send-email-tiberiu.a.breana@intel.com>

Added suspend & resume functions to the stk3310 driver.

Signed-off-by: Tiberiu Breana <tiberiu.a.breana@intel.com>
---
 drivers/iio/light/stk3310.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 5bcf5a0..bc09304 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -82,6 +82,8 @@ enum stk3310_config_type {
 struct stk3310_data {
 	struct i2c_client *client;
 	struct mutex lock;
+	int als_enabled;
+	int ps_enabled;
 	/* Cache table for storing config values */
 	int cache[2][STK3310_TYPE_COUNT];
 };
@@ -385,6 +387,12 @@ static int stk3310_set_state(struct stk3310_data *data, u8 state)
 
 	mutex_unlock(&data->lock);
 
+	/* Don't reset the 'enabled' flags if we're going in standby */
+	if (state != STK3310_STATE_STANDBY) {
+		data->ps_enabled = (state & 0x01) ? 1 : 0;
+		data->als_enabled = (state & 0x02) ? 1 : 0;
+	}
+
 	return ret;
 }
 
@@ -461,6 +469,38 @@ static int stk3310_remove(struct i2c_client *client)
 	return stk3310_set_state(data, STK3310_STATE_STANDBY);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int stk3310_suspend(struct device *dev)
+{
+	struct stk3310_data *data;
+
+	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
+
+	return stk3310_set_state(data, STK3310_STATE_STANDBY);
+}
+
+static int stk3310_resume(struct device *dev)
+{
+	int state;
+	struct stk3310_data *data;
+
+	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
+	state = 0;
+	if (data->ps_enabled)
+		state |= STK3310_STATE_EN_PS;
+	if (data->als_enabled)
+		state |= STK3310_STATE_EN_ALS;
+
+	return stk3310_set_state(data, state);
+}
+
+static SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend, stk3310_resume);
+
+#define STK3310_PM_OPS (&stk3310_pm_ops)
+#else
+#define STK3310_PM_OPS NULL
+#endif
+
 static const struct i2c_device_id stk3310_i2c_id[] = {
 	{"STK3310", 0},
 	{"STK3311", 0},
@@ -478,6 +518,7 @@ MODULE_DEVICE_TABLE(acpi, stk3310_acpi_id);
 static struct i2c_driver stk3310_driver = {
 	.driver = {
 		.name = "stk3310",
+		.pm = STK3310_PM_OPS,
 		.acpi_match_table = ACPI_PTR(stk3310_acpi_id),
 	},
 	.probe =            stk3310_probe,
-- 
1.9.1

  parent reply	other threads:[~2015-04-14  9:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14  9:32 [PATCH 0/3] Add support for Sensortek STK3310 Tiberiu Breana
2015-04-14  9:32 ` [PATCH 1/3] iio: light: " Tiberiu Breana
2015-04-19 15:54   ` Jonathan Cameron
2015-04-14  9:32 ` Tiberiu Breana [this message]
2015-04-19 15:57   ` [PATCH 2/3] iio: light: Add Power Management for STK3310 Jonathan Cameron
2015-04-14  9:32 ` [PATCH 3/3] iio: light: Add threshold interrupt support " Tiberiu Breana
2015-04-19 16:08   ` 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=1429003962-13922-3-git-send-email-tiberiu.a.breana@intel.com \
    --to=tiberiu.a.breana@intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.