From 7413dd10826ecb42cc2ee6b0a7919be2b290dd57 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Wed, 21 Oct 2020 12:57:22 -0700 Subject: driver: use IS_ENABLED on more accelerometer drivers BUG=chromium:1140877 BRANCH=none TEST=buildall Change-Id: I3c45918b628d4f0999842922680a948cdd4933a2 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2491267 Reviewed-by: Ching-Kang Yen --- driver/accelgyro_lsm6dsm.c | 139 ++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 71 deletions(-) (limited to 'driver/accelgyro_lsm6dsm.c') diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c index 64a1d22517..3383d36741 100644 --- a/driver/accelgyro_lsm6dsm.c +++ b/driver/accelgyro_lsm6dsm.c @@ -67,9 +67,7 @@ static inline enum dev_fifo get_fifo_type(const struct motion_sensor_t *s) static enum dev_fifo map[] = { FIFO_DEV_ACCEL, FIFO_DEV_GYRO, -#ifdef CONFIG_LSM6DSM_SEC_I2C FIFO_DEV_MAG -#endif /* CONFIG_LSM6DSM_SEC_I2C */ }; return map[s->type]; } @@ -225,40 +223,44 @@ static int fifo_enable(const struct motion_sensor_t *accel) LSM6DSM_FIFO_CTRL3_ADDR, (decimators[FIFO_DEV_GYRO] << LSM6DSM_FIFO_DEC_G_OFF) | (decimators[FIFO_DEV_ACCEL] << LSM6DSM_FIFO_DEC_XL_OFF)); -#ifdef CONFIG_LSM6DSM_SEC_I2C - st_raw_write8(accel->port, accel->i2c_spi_addr_flags, - LSM6DSM_FIFO_CTRL4_ADDR, - decimators[FIFO_DEV_MAG]); + if (IS_ENABLED(CONFIG_LSM6DSM_SEC_I2C)) { + st_raw_write8(accel->port, accel->i2c_spi_addr_flags, + LSM6DSM_FIFO_CTRL4_ADDR, + decimators[FIFO_DEV_MAG]); - /* - * FIFO ODR is limited by odr of gyro or accel. - * If we are sampling magnetometer faster than gyro or accel, - * bump up ODR of accel. Thanks to decimation we will still measure at - * the specified ODR. - * Contrary to gyroscope, sampling faster will not affect measurements. - * Set the ODR behind the back of set/get_data_rate. - * - * First samples after ODR changes must be thrown out [See - * AN4987, section 3.9]. - * When increasing accel ODR, the FIFO is going to drop samples, - * - except the first one after ODR change. - * When decreasing accel ODR, we don't need to drop sample if - * frequency is less than 52Hz. - * At most, we need to drop one sample, but Android requirement specify - * that chaning one sensor ODR should not affect other sensors. - * Leave the bad sample alone, it will be a single glitch in the - * accelerometer data stream. - */ - if (max_odr > MAX(odrs[FIFO_DEV_ACCEL], odrs[FIFO_DEV_GYRO])) { - st_write_data_with_mask(accel, LSM6DSM_ODR_REG(accel->type), + /* + * FIFO ODR is limited by odr of gyro or accel. + * If we are sampling magnetometer faster than gyro or accel, + * bump up ODR of accel. Thanks to decimation we will still + * measure at the specified ODR. + * Contrary to gyroscope, sampling faster will not affect + * measurements. + * Set the ODR behind the back of set/get_data_rate. + * + * First samples after ODR changes must be thrown out [See + * AN4987, section 3.9]. + * When increasing accel ODR, the FIFO is going to drop samples, + * - except the first one after ODR change. + * When decreasing accel ODR, we don't need to drop sample if + * frequency is less than 52Hz. + * At most, we need to drop one sample, but Android requirement + * specify that changing one sensor ODR should not affect other + * sensors. + * Leave the bad sample alone, it will be a single glitch in the + * accelerometer data stream. + */ + if (max_odr > MAX(odrs[FIFO_DEV_ACCEL], odrs[FIFO_DEV_GYRO])) { + st_write_data_with_mask(accel, + LSM6DSM_ODR_REG(accel->type), LSM6DSM_ODR_MASK, LSM6DSM_ODR_TO_REG(max_odr)); - } else { - st_write_data_with_mask(accel, LSM6DSM_ODR_REG(accel->type), + } else { + st_write_data_with_mask(accel, + LSM6DSM_ODR_REG(accel->type), LSM6DSM_ODR_MASK, LSM6DSM_ODR_TO_REG(odrs[FIFO_DEV_ACCEL])); + } } -#endif /* CONFIG_MAG_LSM6DSM_LIS2MDL */ /* * After ODR and decimation values are set, continuous mode can be * enabled @@ -347,13 +349,11 @@ static void push_fifo_data(struct motion_sensor_t *accel, uint8_t *fifo, axis = s->raw_xyz; /* Apply precision, sensitivity and rotation. */ -#ifdef CONFIG_MAG_LSM6DSM_LIS2MDL - if (s->type == MOTIONSENSE_TYPE_MAG) { + if (IS_ENABLED(CONFIG_MAG_LSM6DSM_LIS2MDL) && + (s->type == MOTIONSENSE_TYPE_MAG)) { lis2mdl_normalize(s, axis, fifo); rotate(axis, *s->rot_standard_ref, axis); - } else -#endif - { + } else { st_normalize(s, axis, fifo); } @@ -609,12 +609,12 @@ int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd) return EC_RES_INVALID_PARAM; } -#ifdef CONFIG_MAG_LSM6DSM_LIS2MDL /* * TODO(b:110143516) Improve data rate selection: * Sensor is always running at 100Hz, even when not used. */ - if (s->type == MOTIONSENSE_TYPE_MAG) { + if (IS_ENABLED(CONFIG_MAG_LSM6DSM_LIS2MDL) && + (s->type == MOTIONSENSE_TYPE_MAG)) { struct mag_cal_t *cal = LIS2MDL_CAL(s); init_mag_cal(cal); @@ -631,9 +631,7 @@ int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd) cal->batch_size = 0; CPRINTS("Batch size: %d", cal->batch_size); mutex_lock(s->mutex); - } else -#endif - { + } else { mutex_lock(s->mutex); ctrl_reg = LSM6DSM_ODR_REG(s->type); ret = st_write_data_with_mask(s, ctrl_reg, LSM6DSM_ODR_MASK, @@ -767,37 +765,37 @@ static int init(const struct motion_sensor_t *s) if (ret != EC_SUCCESS) goto err_unlock; -#ifdef CONFIG_LSM6DSM_SEC_I2C - /* - * Reboot to reload memory content as pass-through mode can get - * stuck. - * Direct to the AN: See "AN4987 - LSM6DSM: always-on 3D - * accelerometer and 3D gyroscope". - */ - - /* Power ON Accel. */ - ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, - ctrl_reg, reg_val); - if (ret != EC_SUCCESS) - goto err_unlock; + if (IS_ENABLED(CONFIG_LSM6DSM_SEC_I2C)) { + /* + * Reboot to reload memory content as pass-through mode + * can get stuck. + * Direct to the AN: See "AN4987 - LSM6DSM: always-on 3D + * accelerometer and 3D gyroscope". + */ + + /* Power ON Accel. */ + ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, + ctrl_reg, reg_val); + if (ret != EC_SUCCESS) + goto err_unlock; - ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, - LSM6DSM_CTRL3_ADDR, LSM6DSM_BOOT); - if (ret != EC_SUCCESS) - goto err_unlock; + ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, + LSM6DSM_CTRL3_ADDR, LSM6DSM_BOOT); + if (ret != EC_SUCCESS) + goto err_unlock; - /* - * Refer to AN4987, wait 15ms for accelerometer to doing full - * reboot. - */ - msleep(15); + /* + * Refer to AN4987, wait 15ms for accelerometer to doing + * full reboot. + */ + msleep(15); - /* Power OFF Accel. */ - ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, - ctrl_reg, 0); - if (ret != EC_SUCCESS) - goto err_unlock; -#endif + /* Power OFF Accel. */ + ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, + ctrl_reg, 0); + if (ret != EC_SUCCESS) + goto err_unlock; + } /* * Output data not updated until have been read. @@ -817,11 +815,10 @@ static int init(const struct motion_sensor_t *s) goto err_unlock; } -#ifdef CONFIG_ACCEL_INTERRUPTS - ret = config_interrupt(s); + if (IS_ENABLED(CONFIG_ACCEL_INTERRUPTS)) + ret = config_interrupt(s); if (ret != EC_SUCCESS) goto err_unlock; -#endif /* CONFIG_ACCEL_INTERRUPTS */ mutex_unlock(s->mutex); } -- cgit v1.2.1