summaryrefslogtreecommitdiff
path: root/drivers/iio/accel/mma8452.c
diff options
context:
space:
mode:
authorMartin Kepplinger <martink@posteo.de>2016-03-03 11:24:02 +0300
committerJonathan Cameron <jic23@kernel.org>2016-03-05 20:22:16 +0300
commite866853d67868ac0f7e0779d19aaad07285c9ff3 (patch)
treeb1bf6e737e28e33ade067b725544978608605b27 /drivers/iio/accel/mma8452.c
parent8b8ff3a6a6e2325662e3af174f54b47487d3ed75 (diff)
downloadlinux-e866853d67868ac0f7e0779d19aaad07285c9ff3.tar.xz
iio: mma8452: avoid switching to active because of config change
The devices' config registers can only be changed in standby mode. Up until now the driver just held the device *always* active, so for changing a config it was *always* necessary to switch to standby. For upcoming support for runtime pm, the device can as well be in standby mode. Instead of putting runtime pm functions in there, just keep the device in standby if it already is. This section is protected by a lock after all. Signed-off-by: Martin Kepplinger <martink@posteo.de> Signed-off-by: Christoph Muellner <christoph.muellner@theobroma-systems.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/accel/mma8452.c')
-rw-r--r--drivers/iio/accel/mma8452.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 17d72bc2e6fa..9c4a84a72ad4 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -393,24 +393,47 @@ static int mma8452_active(struct mma8452_data *data)
data->ctrl_reg1);
}
+/* returns >0 if active, 0 if in standby and <0 on error */
+static int mma8452_is_active(struct mma8452_data *data)
+{
+ int reg;
+
+ reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG1);
+ if (reg < 0)
+ return reg;
+
+ return reg & MMA8452_CTRL_ACTIVE;
+}
+
static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
{
int ret;
+ int is_active;
mutex_lock(&data->lock);
- /* config can only be changed when in standby */
- ret = mma8452_standby(data);
- if (ret < 0)
+ is_active = mma8452_is_active(data);
+ if (is_active < 0) {
+ ret = is_active;
goto fail;
+ }
+
+ /* config can only be changed when in standby */
+ if (is_active > 0) {
+ ret = mma8452_standby(data);
+ if (ret < 0)
+ goto fail;
+ }
ret = i2c_smbus_write_byte_data(data->client, reg, val);
if (ret < 0)
goto fail;
- ret = mma8452_active(data);
- if (ret < 0)
- goto fail;
+ if (is_active > 0) {
+ ret = mma8452_active(data);
+ if (ret < 0)
+ goto fail;
+ }
ret = 0;
fail: