iio: imu: st_lsm6dsx: introduce st_lsm6dsx_sensor_set_enable routine
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Sun, 11 Nov 2018 14:15:32 +0000 (15:15 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 16 Nov 2018 18:32:33 +0000 (18:32 +0000)
Add st_lsm6dsx_sensor_set_enable routine and remove
st_lsm6dsx_sensor_{enable/disable} ones in order to make the code more
readable and remove unnecessary functions

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c

index 4c8385d..2beb4f5 100644 (file)
@@ -185,8 +185,8 @@ extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
 
 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
                     struct regmap *regmap);
-int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor);
-int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor);
+int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
+                                bool enable);
 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
 int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val);
 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
index f480400..6a37976 100644 (file)
@@ -579,15 +579,9 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
                        goto out;
        }
 
-       if (enable) {
-               err = st_lsm6dsx_sensor_enable(sensor);
-               if (err < 0)
-                       goto out;
-       } else {
-               err = st_lsm6dsx_sensor_disable(sensor);
-               if (err < 0)
-                       goto out;
-       }
+       err = st_lsm6dsx_sensor_set_enable(sensor, enable);
+       if (err < 0)
+               goto out;
 
        err = st_lsm6dsx_set_fifo_odr(sensor, enable);
        if (err < 0)
index 8885c97..28ddedb 100644 (file)
@@ -530,33 +530,21 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
        return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
 }
 
-int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
-{
-       int err;
-
-       err = st_lsm6dsx_set_odr(sensor, sensor->odr);
-       if (err < 0)
-               return err;
-
-       sensor->hw->enable_mask |= BIT(sensor->id);
-
-       return 0;
-}
-
-int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor)
+int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
+                                bool enable)
 {
        struct st_lsm6dsx_hw *hw = sensor->hw;
-       const struct st_lsm6dsx_reg *reg;
-       unsigned int data;
+       u16 odr = enable ? sensor->odr : 0;
        int err;
 
-       reg = &st_lsm6dsx_odr_table[sensor->id].reg;
-       data = ST_LSM6DSX_SHIFT_VAL(0, reg->mask);
-       err = st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data);
+       err = st_lsm6dsx_set_odr(sensor, odr);
        if (err < 0)
                return err;
 
-       sensor->hw->enable_mask &= ~BIT(sensor->id);
+       if (enable)
+               hw->enable_mask |= BIT(sensor->id);
+       else
+               hw->enable_mask &= ~BIT(sensor->id);
 
        return 0;
 }
@@ -568,7 +556,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
        int err, delay;
        __le16 data;
 
-       err = st_lsm6dsx_sensor_enable(sensor);
+       err = st_lsm6dsx_sensor_set_enable(sensor, true);
        if (err < 0)
                return err;
 
@@ -579,7 +567,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
        if (err < 0)
                return err;
 
-       st_lsm6dsx_sensor_disable(sensor);
+       st_lsm6dsx_sensor_set_enable(sensor, false);
 
        *val = (s16)le16_to_cpu(data);