iio: imu: inv_mpu6050: early init of chip_config for use at setup
authorJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Wed, 19 Feb 2020 14:39:50 +0000 (15:39 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 8 Mar 2020 17:28:37 +0000 (17:28 +0000)
Init chip_config early and use its values for initial setup.
More coherent, prevent possible mistakes.

Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

index 0b06d6a..85872e5 100644 (file)
@@ -101,7 +101,7 @@ static const struct inv_mpu6050_reg_map reg_set_6050 = {
 static const struct inv_mpu6050_chip_config chip_config_6050 = {
        .fsr = INV_MPU6050_FSR_2000DPS,
        .lpf = INV_MPU6050_FILTER_20HZ,
-       .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE),
+       .divider = INV_MPU6050_FIFO_RATE_TO_DIVIDER(50),
        .gyro_fifo_enable = false,
        .accl_fifo_enable = false,
        .temp_fifo_enable = false,
@@ -370,20 +370,20 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
        u8 d;
        struct inv_mpu6050_state *st = iio_priv(indio_dev);
 
-       result = inv_mpu6050_set_gyro_fsr(st, INV_MPU6050_FSR_2000DPS);
+       result = inv_mpu6050_set_gyro_fsr(st, st->chip_config.fsr);
        if (result)
                return result;
 
-       result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ);
+       result = inv_mpu6050_set_lpf_regs(st, st->chip_config.lpf);
        if (result)
                return result;
 
-       d = INV_MPU6050_FIFO_RATE_TO_DIVIDER(INV_MPU6050_INIT_FIFO_RATE);
+       d = st->chip_config.divider;
        result = regmap_write(st->map, st->reg->sample_rate_div, d);
        if (result)
                return result;
 
-       d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
+       d = (st->chip_config.accl_fs << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
        result = regmap_write(st->map, st->reg->accl_config, d);
        if (result)
                return result;
@@ -392,9 +392,6 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
        if (result)
                return result;
 
-       memcpy(&st->chip_config, hw_info[st->chip_type].config,
-              sizeof(struct inv_mpu6050_chip_config));
-
        /*
         * Internal chip period is 1ms (1kHz).
         * Let's use at the beginning the theorical value before measuring
@@ -1116,6 +1113,8 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
 
        st->hw  = &hw_info[st->chip_type];
        st->reg = hw_info[st->chip_type].reg;
+       memcpy(&st->chip_config, hw_info[st->chip_type].config,
+              sizeof(st->chip_config));
 
        /* check chip self-identification */
        result = regmap_read(st->map, INV_MPU6050_REG_WHOAMI, &regval);
index 9a81098..d5edf90 100644 (file)
@@ -321,7 +321,6 @@ struct inv_mpu6050_state {
 #define INV_MPU6050_TS_PERIOD_JITTER   4
 
 /* init parameters */
-#define INV_MPU6050_INIT_FIFO_RATE           50
 #define INV_MPU6050_MAX_FIFO_RATE            1000
 #define INV_MPU6050_MIN_FIFO_RATE            4