Skip to content

Commit 17623d9

Browse files
jmaneyrol-invnjic23
authored andcommitted
iio: imu: inv_mpu6050: use set_power_itg function in i2c mux
Set power function is rewritten manually inside i2c mux select. Better use the already identical existing function. Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 7fc0168 commit 17623d9

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,19 @@ static int inv_mpu6050_select_bypass(struct i2c_mux_core *muxc, u32 chan_id)
2929
{
3030
struct iio_dev *indio_dev = i2c_mux_priv(muxc);
3131
struct inv_mpu6050_state *st = iio_priv(indio_dev);
32-
int ret = 0;
32+
int ret;
3333

34-
/* Use the same mutex which was used everywhere to protect power-op */
3534
mutex_lock(&st->lock);
36-
if (!st->powerup_count) {
37-
ret = regmap_write(st->map, st->reg->pwr_mgmt_1, 0);
38-
if (ret)
39-
goto write_error;
4035

41-
usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
42-
INV_MPU6050_REG_UP_TIME_MAX);
43-
}
44-
if (!ret) {
45-
st->powerup_count++;
46-
ret = regmap_write(st->map, st->reg->int_pin_cfg,
47-
INV_MPU6050_INT_PIN_CFG |
48-
INV_MPU6050_BIT_BYPASS_EN);
49-
}
50-
write_error:
36+
ret = inv_mpu6050_set_power_itg(st, true);
37+
if (ret)
38+
goto error_unlock;
39+
40+
ret = regmap_write(st->map, st->reg->int_pin_cfg,
41+
INV_MPU6050_INT_PIN_CFG |
42+
INV_MPU6050_BIT_BYPASS_EN);
43+
44+
error_unlock:
5145
mutex_unlock(&st->lock);
5246

5347
return ret;
@@ -59,12 +53,11 @@ static int inv_mpu6050_deselect_bypass(struct i2c_mux_core *muxc, u32 chan_id)
5953
struct inv_mpu6050_state *st = iio_priv(indio_dev);
6054

6155
mutex_lock(&st->lock);
56+
6257
/* It doesn't really mattter, if any of the calls fails */
6358
regmap_write(st->map, st->reg->int_pin_cfg, INV_MPU6050_INT_PIN_CFG);
64-
st->powerup_count--;
65-
if (!st->powerup_count)
66-
regmap_write(st->map, st->reg->pwr_mgmt_1,
67-
INV_MPU6050_BIT_SLEEP);
59+
inv_mpu6050_set_power_itg(st, false);
60+
6861
mutex_unlock(&st->lock);
6962

7063
return 0;

0 commit comments

Comments
 (0)