Commit edddddd9 authored by Jean-Baptiste Maneyrol's avatar Jean-Baptiste Maneyrol Committed by Jonathan Cameron

iio: imu: inv_mpu6050: fix user_ctrl register overwritten

When in spi mode, we are setting i2c disable bit in user_ctrl
register. But the register is overwritten after when turning fifo
on. So save user_ctrl init value and always use it when updating
the register.
Signed-off-by: default avatarJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c2b82a69
...@@ -88,6 +88,7 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = { ...@@ -88,6 +88,7 @@ static const struct inv_mpu6050_chip_config chip_config_6050 = {
.gyro_fifo_enable = false, .gyro_fifo_enable = false,
.accl_fifo_enable = false, .accl_fifo_enable = false,
.accl_fs = INV_MPU6050_FS_02G, .accl_fs = INV_MPU6050_FS_02G,
.user_ctrl = 0,
}; };
/* Indexed by enum inv_devices */ /* Indexed by enum inv_devices */
...@@ -972,15 +973,15 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, ...@@ -972,15 +973,15 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
if (result) if (result)
return result; return result;
if (inv_mpu_bus_setup)
inv_mpu_bus_setup(indio_dev);
result = inv_mpu6050_init_config(indio_dev); result = inv_mpu6050_init_config(indio_dev);
if (result) { if (result) {
dev_err(dev, "Could not initialize device.\n"); dev_err(dev, "Could not initialize device.\n");
return result; return result;
} }
if (inv_mpu_bus_setup)
inv_mpu_bus_setup(indio_dev);
dev_set_drvdata(dev, indio_dev); dev_set_drvdata(dev, indio_dev);
indio_dev->dev.parent = dev; indio_dev->dev.parent = dev;
/* name will be NULL when enumerated via ACPI */ /* name will be NULL when enumerated via ACPI */
......
...@@ -97,6 +97,7 @@ struct inv_mpu6050_chip_config { ...@@ -97,6 +97,7 @@ struct inv_mpu6050_chip_config {
unsigned int accl_fifo_enable:1; unsigned int accl_fifo_enable:1;
unsigned int gyro_fifo_enable:1; unsigned int gyro_fifo_enable:1;
u16 fifo_rate; u16 fifo_rate;
u8 user_ctrl;
}; };
/** /**
......
...@@ -51,13 +51,14 @@ int inv_reset_fifo(struct iio_dev *indio_dev) ...@@ -51,13 +51,14 @@ int inv_reset_fifo(struct iio_dev *indio_dev)
if (result) if (result)
goto reset_fifo_fail; goto reset_fifo_fail;
/* disable fifo reading */ /* disable fifo reading */
result = regmap_write(st->map, st->reg->user_ctrl, 0); result = regmap_write(st->map, st->reg->user_ctrl,
st->chip_config.user_ctrl);
if (result) if (result)
goto reset_fifo_fail; goto reset_fifo_fail;
/* reset FIFO*/ /* reset FIFO*/
result = regmap_write(st->map, st->reg->user_ctrl, d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST;
INV_MPU6050_BIT_FIFO_RST); result = regmap_write(st->map, st->reg->user_ctrl, d);
if (result) if (result)
goto reset_fifo_fail; goto reset_fifo_fail;
...@@ -72,9 +73,9 @@ int inv_reset_fifo(struct iio_dev *indio_dev) ...@@ -72,9 +73,9 @@ int inv_reset_fifo(struct iio_dev *indio_dev)
if (result) if (result)
return result; return result;
} }
/* enable FIFO reading and I2C master interface*/ /* enable FIFO reading */
result = regmap_write(st->map, st->reg->user_ctrl, d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_EN;
INV_MPU6050_BIT_FIFO_EN); result = regmap_write(st->map, st->reg->user_ctrl, d);
if (result) if (result)
goto reset_fifo_fail; goto reset_fifo_fail;
/* enable sensor output to FIFO */ /* enable sensor output to FIFO */
......
...@@ -31,8 +31,9 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev) ...@@ -31,8 +31,9 @@ static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
if (ret) if (ret)
return ret; return ret;
ret = regmap_write(st->map, INV_MPU6050_REG_USER_CTRL, st->chip_config.user_ctrl |= INV_MPU6050_BIT_I2C_IF_DIS;
INV_MPU6050_BIT_I2C_IF_DIS); ret = regmap_write(st->map, st->reg->user_ctrl,
st->chip_config.user_ctrl);
if (ret) { if (ret) {
inv_mpu6050_set_power_itg(st, false); inv_mpu6050_set_power_itg(st, false);
return ret; return ret;
......
...@@ -76,7 +76,8 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) ...@@ -76,7 +76,8 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
if (result) if (result)
goto error_accl_off; goto error_accl_off;
result = regmap_write(st->map, st->reg->user_ctrl, 0); result = regmap_write(st->map, st->reg->user_ctrl,
st->chip_config.user_ctrl);
if (result) if (result)
goto error_accl_off; goto error_accl_off;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment