/** * inv_mpu6050_set_enable() - enable chip functions. * @indio_dev: Device driver instance. * @enable: enable/disable */ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) { struct inv_mpu6050_state *st = iio_priv(indio_dev); int result; if (enable) { result = inv_mpu6050_set_power_itg(st, true); if (result) return result; inv_scan_query(indio_dev); if (st->chip_config.gyro_fifo_enable) { result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) return result; } if (st->chip_config.accl_fifo_enable) { result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_BIT_PWR_ACCL_STBY); if (result) return result; } result = inv_reset_fifo(indio_dev); if (result) return result; } else { result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); if (result) return result; result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); if (result) return result; result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); if (result) return result; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) return result; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_ACCL_STBY); if (result) return result; result = inv_mpu6050_set_power_itg(st, false); if (result) return result; } st->chip_config.enable = enable; return 0; }
int inv_reset_fifo(struct iio_dev *indio_dev) { int result; u8 d; struct inv_mpu6050_state *st = iio_priv(indio_dev); /* disable interrupt */ result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0); if (result) { dev_err(&st->client->dev, "int_enable failed %d\n", result); return result; } /* disable the sensor output to FIFO */ result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0); if (result) goto reset_fifo_fail; /* disable fifo reading */ result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0); if (result) goto reset_fifo_fail; /* reset FIFO*/ result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, INV_MPU6050_BIT_FIFO_RST); if (result) goto reset_fifo_fail; /* enable interrupt */ if (st->chip_config.accl_fifo_enable || st->chip_config.gyro_fifo_enable) { result = inv_mpu6050_write_reg(st, st->reg->int_enable, INV_MPU6050_BIT_DATA_RDY_EN); if (result) return result; } /* enable FIFO reading and I2C master interface*/ result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, INV_MPU6050_BIT_FIFO_EN); if (result) goto reset_fifo_fail; /* enable sensor output to FIFO */ d = 0; if (st->chip_config.gyro_fifo_enable) d |= INV_MPU6050_BITS_GYRO_OUT; if (st->chip_config.accl_fifo_enable) d |= INV_MPU6050_BIT_ACCEL_OUT; result = inv_mpu6050_write_reg(st, st->reg->fifo_en, d); if (result) goto reset_fifo_fail; return 0; reset_fifo_fail: dev_err(&st->client->dev, "reset fifo failed %d\n", result); result = inv_mpu6050_write_reg(st, st->reg->int_enable, INV_MPU6050_BIT_DATA_RDY_EN); return result; }