<commit_before>/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* BMI160 accelerometer and gyro and BMM150 compass module for Chrome EC */

#ifndef __CROS_EC_ACCELGYRO_BMI160_H
#define __CROS_EC_ACCELGYRO_BMI160_H

#include "accelgyro.h"
#include "mag_bmm150.h"

/*
 * The addr field of motion_sensor support both SPI and I2C:
 * This is defined in include/i2c.h and is no longer an 8bit
 * address. The 7/10 bit address starts at bit 0 and leaves
 * room for a 10 bit address, although we don't currently
 * have any 10 bit slaves.  I2C or SPI is indicated by a
 * more significant bit
 */

/* I2C addresses */
#define BMI160_ADDR0_FLAGS	0x68
#define BMI160_ADDR1_FLAGS	0x69

#define BMI160_CHIP_ID           0x00
#define BMI160_CHIP_ID_MAJOR     0xd1
#define BMI168_CHIP_ID_MAJOR     0xd2

#define BMI160_SPEC_ACC_STARTUP_TIME_MS     10
#define BMI160_SPEC_GYR_STARTUP_TIME_MS     80
#define BMI160_SPEC_MAG_STARTUP_TIME_MS     60


#define BMI160_ERR_REG         0x02
#define BMI160_PMU_STATUS      0x03
#define BMI160_PMU_MAG_OFFSET               0
#define BMI160_PMU_GYR_OFFSET               2
#define BMI160_PMU_ACC_OFFSET               4
#define BMI160_PMU_SENSOR_STATUS(_sensor_type, _val) \
	(((_val) >> (4 - 2 * (_sensor_type))) & 0x3)
#define BMI160_PMU_SUSPEND                  0
#define BMI160_PMU_NORMAL                   1
#define BMI160_PMU_LOW_POWER                2
#define BMI160_PMU_FAST_STARTUP             3

#define BMI160_MAG_X_L_G       0x04
#define BMI160_MAG_X_H_G       0x05
#define BMI160_MAG_Y_L_G       0x06
#define BMI160_MAG_Y_H_G       0x07
#define BMI160_MAG_Z_L_G       0x08
#define BMI160_MAG_Z_H_G       0x09
#define BMI160_RHALL_L_G       0x0a
#define BMI160_RHALL_H_G       0x0b
#define BMI160_GYR_X_L_G       0x0c
#define BMI160_GYR_X_H_G       0x0d
#define BMI160_GYR_Y_L_G       0x0e
#define BMI160_GYR_Y_H_G       0x0f
#define BMI160_GYR_Z_L_G       0x10
#define BMI160_GYR_Z_H_G       0x11
#define BMI160_ACC_X_L_G       0x12
#define BMI160_ACC_X_H_G       0x13
#define BMI160_ACC_Y_L_G       0x14
#define BMI160_ACC_Y_H_G       0x15
#define BMI160_ACC_Z_L_G       0x16
#define BMI160_ACC_Z_H_G       0x17

#define BMI160_SENSORTIME_0    0x18
#define BMI160_SENSORTIME_1    0x19
#define BMI160_SENSORTIME_2    0x1a

#define BMI160_STATUS          0x1b
#define BMI160_POR_DETECTED        BIT(0)
#define BMI160_GYR_SLF_TST         BIT(1)
#define BMI160_MAG_MAN_OP          BIT(2)
#define BMI160_FOC_RDY             BIT(3)
#define BMI160_NVM_RDY             BIT(4)
#define BMI160_DRDY_MAG            BIT(5)
#define BMI160_DRDY_GYR            BIT(6)
#define BMI160_DRDY_ACC            BIT(7)
#define BMI160_DRDY_OFF(_sensor)   (7 - (_sensor))
#define BMI160_DRDY_MASK(_sensor)  (1 << BMI160_DRDY_OFF(_sensor))

/* first 2 bytes are the interrupt reasons, next 2 some qualifier */
#define BMI160_INT_STATUS_0    0x1c
#define BMI160_STEP_INT            BIT(0)
#define BMI160_SIGMOT_INT          BIT(1)
#define BMI160_ANYM_INT            BIT(2)
#define BMI160_PMU_TRIGGER_INT     BIT(3)
#define BMI160_D_TAP_INT           BIT(4)
#define BMI160_S_TAP_INT           BIT(5)
#define BMI160_ORIENT_INT          BIT(6)
#define BMI160_FLAT_INT            BIT(7)
#define BMI160_ORIENT_XY_MASK	   0x30
#define BMI160_ORIENT_PORTRAIT		(0 << 4)
#define BMI160_ORIENT_PORTRAIT_INVERT	BIT(4)
#define BMI160_ORIENT_LANDSCAPE		(2 << 4)
#define BMI160_ORIENT_LANDSCAPE_INVERT	(3 << 4)


#define BMI160_INT_STATUS_1    0x1d
#define BMI160_HIGHG_INT           (1 << (2 + 8))
#define BMI160_LOWG_INT            (1 << (3 + 8))
#define BMI160_DRDY_INT            (1 << (4 + 8))
#define BMI160_FFULL_INT           (1 << (5 + 8))
#define BMI160_FWM_INT             (1 << (6 + 8))
#define BMI160_NOMO_INT            (1 << (7 + 8))

#define BMI160_INT_MASK            0xFFFF

#define BMI160_INT_STATUS_2    0x1e
#define BMI160_INT_STATUS_3    0x1f
#define BMI160_FIRST_X             (1 << (0 + 16))
#define BMI160_FIRST_Y             (1 << (1 + 16))
#define BMI160_FIRST_Z             (1 << (2 + 16))
#define BMI160_SIGN                (1 << (3 + 16))
#define BMI160_ANYM_OFFSET         0
#define BMI160_TAP_OFFSET          4
#define BMI160_HIGH_OFFSET         8
#define BMI160_INT_INFO(_type, _data) \
(CONCAT2(BMI160_, _data) << CONCAT3(BMI160_, _type, _OFFSET))

#define BMI160_ORIENT_Z            (1 << (6 + 24))
#define BMI160_FLAT                (1 << (7 + 24))

#define BMI160_TEMPERATURE_0   0x20
#define BMI160_TEMPERATURE_1   0x21
#define BMI160_INVALID_TEMP        0x8000


#define BMI160_FIFO_LENGTH_0   0x22
#define BMI160_FIFO_LENGTH_1   0x23
#define BMI160_FIFO_LENGTH_MASK    (BIT(11) - 1)
#define BMI160_FIFO_DATA       0x24
enum fifo_header {
	BMI160_EMPTY = 0x80,
	BMI160_SKIP = 0x40,
	BMI160_TIME = 0x44,
	BMI160_CONFIG = 0x48
};

#define BMI160_FH_MODE_MASK    0xc0
#define BMI160_FH_PARM_OFFSET    2
#define BMI160_FH_PARM_MASK    (0x7 << BMI160_FH_PARM_OFFSET)
#define BMI160_FH_EXT_MASK     0x03


#define BMI160_ACC_CONF        0x40
#define BMI160_ODR_MASK                 0x0F
#define BMI160_ACC_BW_OFFSET            4
#define BMI160_ACC_BW_MASK     (0x7 << BMI160_ACC_BW_OFFSET)

#define BMI160_ACC_RANGE       0x41
#define BMI160_GSEL_2G         0x03
#define BMI160_GSEL_4G         0x05
#define BMI160_GSEL_8G         0x08
#define BMI160_GSEL_16G        0x0c

#define BMI160_GYR_CONF        0x42
#define BMI160_GYR_BW_OFFSET   4
#define BMI160_GYR_BW_MASK     (0x3 << BMI160_GYR_BW_OFFSET)

#define BMI160_GYR_RANGE       0x43
#define BMI160_DPS_SEL_2000    0x00
#define BMI160_DPS_SEL_1000    0x01
#define BMI160_DPS_SEL_500     0x02
#define BMI160_DPS_SEL_250     0x03
#define BMI160_DPS_SEL_125     0x04


#define BMI160_MAG_CONF        0x44

/* odr = 100 / (1 << (8 - reg)) ,within limit */
#define BMI160_ODR_0_78HZ      0x01
#define BMI160_ODR_100HZ       0x08

#define BMI160_REG_TO_ODR(_regval) \
	((_regval) < BMI160_ODR_100HZ ? 100000 / (1 << (8 - (_regval))) : \
					100000 * (1 << ((_regval) - 8)))
#define BMI160_ODR_TO_REG(_odr) \
	((_odr) < 100000 ? (__builtin_clz(100000 / (_odr)) - 24) : \
			   (39 - __builtin_clz((_odr) / 100000)))

#define BMI160_CONF_REG(_sensor)   (0x40 + 2 * (_sensor))
#define BMI160_RANGE_REG(_sensor)  (0x41 + 2 * (_sensor))

#define BMI160_FIFO_DOWNS      0x45
#define BMI160_FIFO_CONFIG_0   0x46
#define BMI160_FIFO_CONFIG_1   0x47
#define BMI160_FIFO_TAG_TIME_EN    BIT(1)
#define BMI160_FIFO_TAG_INT2_EN    BIT(2)
#define BMI160_FIFO_TAG_INT1_EN    BIT(3)
#define BMI160_FIFO_HEADER_EN      BIT(4)
#define BMI160_FIFO_MAG_EN         BIT(5)
#define BMI160_FIFO_ACC_EN         BIT(6)
#define BMI160_FIFO_GYR_EN         BIT(7)
#define BMI160_FIFO_TARG_INT(_i)  CONCAT3(BMI160_FIFO_TAG_INT, _i, _EN)
#define BMI160_FIFO_SENSOR_EN(_sensor) \
	((_sensor) == MOTIONSENSE_TYPE_ACCEL ? BMI160_FIFO_ACC_EN : \
	  ((_sensor) == MOTIONSENSE_TYPE_GYRO ? BMI160_FIFO_GYR_EN : \
	   BMI160_FIFO_MAG_EN))

#define BMI160_MAG_IF_0        0x4b
#define BMI160_MAG_I2C_ADDRESS BMI160_MAG_IF_0<commit_msg>driver: bmi160: Fix ODR to REG when rate is less than 100Hz properly<commit_after>/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* BMI160 accelerometer and gyro and BMM150 compass module for Chrome EC */

#ifndef __CROS_EC_ACCELGYRO_BMI160_H
#define __CROS_EC_ACCELGYRO_BMI160_H

#include "accelgyro.h"
#include "mag_bmm150.h"

/*
 * The addr field of motion_sensor support both SPI and I2C:
 * This is defined in include/i2c.h and is no longer an 8bit
 * address. The 7/10 bit address starts at bit 0 and leaves
 * room for a 10 bit address, although we don't currently
 * have any 10 bit slaves.  I2C or SPI is indicated by a
 * more significant bit
 */

/* I2C addresses */
#define BMI160_ADDR0_FLAGS	0x68
#define BMI160_ADDR1_FLAGS	0x69

#define BMI160_CHIP_ID           0x00
#define BMI160_CHIP_ID_MAJOR     0xd1
#define BMI168_CHIP_ID_MAJOR     0xd2

#define BMI160_SPEC_ACC_STARTUP_TIME_MS     10
#define BMI160_SPEC_GYR_STARTUP_TIME_MS     80
#define BMI160_SPEC_MAG_STARTUP_TIME_MS     60


#define BMI160_ERR_REG         0x02
#define BMI160_PMU_STATUS      0x03
#define BMI160_PMU_MAG_OFFSET               0
#define BMI160_PMU_GYR_OFFSET               2
#define BMI160_PMU_ACC_OFFSET               4
#define BMI160_PMU_SENSOR_STATUS(_sensor_type, _val) \
	(((_val) >> (4 - 2 * (_sensor_type))) & 0x3)
#define BMI160_PMU_SUSPEND                  0
#define BMI160_PMU_NORMAL                   1
#define BMI160_PMU_LOW_POWER                2
#define BMI160_PMU_FAST_STARTUP             3

#define BMI160_MAG_X_L_G       0x04
#define BMI160_MAG_X_H_G       0x05
#define BMI160_MAG_Y_L_G       0x06
#define BMI160_MAG_Y_H_G       0x07
#define BMI160_MAG_Z_L_G       0x08
#define BMI160_MAG_Z_H_G       0x09
#define BMI160_RHALL_L_G       0x0a
#define BMI160_RHALL_H_G       0x0b
#define BMI160_GYR_X_L_G       0x0c
#define BMI160_GYR_X_H_G       0x0d
#define BMI160_GYR_Y_L_G       0x0e
#define BMI160_GYR_Y_H_G       0x0f
#define BMI160_GYR_Z_L_G       0x10
#define BMI160_GYR_Z_H_G       0x11
#define BMI160_ACC_X_L_G       0x12
#define BMI160_ACC_X_H_G       0x13
#define BMI160_ACC_Y_L_G       0x14
#define BMI160_ACC_Y_H_G       0x15
#define BMI160_ACC_Z_L_G       0x16
#define BMI160_ACC_Z_H_G       0x17

#define BMI160_SENSORTIME_0    0x18
#define BMI160_SENSORTIME_1    0x19
#define BMI160_SENSORTIME_2    0x1a

#define BMI160_STATUS          0x1b
#define BMI160_POR_DETECTED        BIT(0)
#define BMI160_GYR_SLF_TST         BIT(1)
#define BMI160_MAG_MAN_OP          BIT(2)
#define BMI160_FOC_RDY             BIT(3)
#define BMI160_NVM_RDY             BIT(4)
#define BMI160_DRDY_MAG            BIT(5)
#define BMI160_DRDY_GYR            BIT(6)
#define BMI160_DRDY_ACC            BIT(7)
#define BMI160_DRDY_OFF(_sensor)   (7 - (_sensor))
#define BMI160_DRDY_MASK(_sensor)  (1 << BMI160_DRDY_OFF(_sensor))

/* first 2 bytes are the interrupt reasons, next 2 some qualifier */
#define BMI160_INT_STATUS_0    0x1c
#define BMI160_STEP_INT            BIT(0)
#define BMI160_SIGMOT_INT          BIT(1)
#define BMI160_ANYM_INT            BIT(2)
#define BMI160_PMU_TRIGGER_INT     BIT(3)
#define BMI160_D_TAP_INT           BIT(4)
#define BMI160_S_TAP_INT           BIT(5)
#define BMI160_ORIENT_INT          BIT(6)
#define BMI160_FLAT_INT            BIT(7)
#define BMI160_ORIENT_XY_MASK	   0x30
#define BMI160_ORIENT_PORTRAIT		(0 << 4)
#define BMI160_ORIENT_PORTRAIT_INVERT	BIT(4)
#define BMI160_ORIENT_LANDSCAPE		(2 << 4)
#define BMI160_ORIENT_LANDSCAPE_INVERT	(3 << 4)


#define BMI160_INT_STATUS_1    0x1d
#define BMI160_HIGHG_INT           (1 << (2 + 8))
#define BMI160_LOWG_INT            (1 << (3 + 8))
#define BMI160_DRDY_INT            (1 << (4 + 8))
#define BMI160_FFULL_INT           (1 << (5 + 8))
#define BMI160_FWM_INT             (1 << (6 + 8))
#define BMI160_NOMO_INT            (1 << (7 + 8))

#define BMI160_INT_MASK            0xFFFF

#define BMI160_INT_STATUS_2    0x1e
#define BMI160_INT_STATUS_3    0x1f
#define BMI160_FIRST_X             (1 << (0 + 16))
#define BMI160_FIRST_Y             (1 << (1 + 16))
#define BMI160_FIRST_Z             (1 << (2 + 16))
#define BMI160_SIGN                (1 << (3 + 16))
#define BMI160_ANYM_OFFSET         0
#define BMI160_TAP_OFFSET          4
#define BMI160_HIGH_OFFSET         8
#define BMI160_INT_INFO(_type, _data) \
(CONCAT2(BMI160_, _data) << CONCAT3(BMI160_, _type, _OFFSET))

#define BMI160_ORIENT_Z            (1 << (6 + 24))
#define BMI160_FLAT                (1 << (7 + 24))

#define BMI160_TEMPERATURE_0   0x20
#define BMI160_TEMPERATURE_1   0x21
#define BMI160_INVALID_TEMP        0x8000


#define BMI160_FIFO_LENGTH_0   0x22
#define BMI160_FIFO_LENGTH_1   0x23
#define BMI160_FIFO_LENGTH_MASK    (BIT(11) - 1)
#define BMI160_FIFO_DATA       0x24
enum fifo_header {
	BMI160_EMPTY = 0x80,
	BMI160_SKIP = 0x40,
	BMI160_TIME = 0x44,
	BMI160_CONFIG = 0x48
};

#define BMI160_FH_MODE_MASK    0xc0
#define BMI160_FH_PARM_OFFSET    2
#define BMI160_FH_PARM_MASK    (0x7 << BMI160_FH_PARM_OFFSET)
#define BMI160_FH_EXT_MASK     0x03


#define BMI160_ACC_CONF        0x40
#define BMI160_ODR_MASK                 0x0F
#define BMI160_ACC_BW_OFFSET            4
#define BMI160_ACC_BW_MASK     (0x7 << BMI160_ACC_BW_OFFSET)

#define BMI160_ACC_RANGE       0x41
#define BMI160_GSEL_2G         0x03
#define BMI160_GSEL_4G         0x05
#define BMI160_GSEL_8G         0x08
#define BMI160_GSEL_16G        0x0c

#define BMI160_GYR_CONF        0x42
#define BMI160_GYR_BW_OFFSET   4
#define BMI160_GYR_BW_MASK     (0x3 << BMI160_GYR_BW_OFFSET)

#define BMI160_GYR_RANGE       0x43
#define BMI160_DPS_SEL_2000    0x00
#define BMI160_DPS_SEL_1000    0x01
#define BMI160_DPS_SEL_500     0x02
#define BMI160_DPS_SEL_250     0x03
#define BMI160_DPS_SEL_125     0x04


#define BMI160_MAG_CONF        0x44

/* odr = 100 / (1 << (8 - reg)) ,within limit */
#define BMI160_ODR_0_78HZ      0x01
#define BMI160_ODR_100HZ       0x08

#define BMI160_REG_TO_ODR(_regval) \
	((_regval) < BMI160_ODR_100HZ ? 100000 / (1 << (8 - (_regval))) : \
					100000 * (1 << ((_regval) - 8)))
#define BMI160_ODR_TO_REG(_odr) \
	((_odr) < 100000 ? (__builtin_clz(100000 / ((_odr) + 1)) - 24) : \
			   (39 - __builtin_clz((_odr) / 100000)))

#define BMI160_CONF_REG(_sensor)   (0x40 + 2 * (_sensor))
#define BMI160_RANGE_REG(_sensor)  (0x41 + 2 * (_sensor))

#define BMI160_FIFO_DOWNS      0x45
#define BMI160_FIFO_CONFIG_0   0x46
#define BMI160_FIFO_CONFIG_1   0x47
#define BMI160_FIFO_TAG_TIME_EN    BIT(1)
#define BMI160_FIFO_TAG_INT2_EN    BIT(2)
#define BMI160_FIFO_TAG_INT1_EN    BIT(3)
#define BMI160_FIFO_HEADER_EN      BIT(4)
#define BMI160_FIFO_MAG_EN         BIT(5)
#define BMI160_FIFO_ACC_EN         BIT(6)
#define BMI160_FIFO_GYR_EN         BIT(7)
#define BMI160_FIFO_TARG_INT(_i)  CONCAT3(BMI160_FIFO_TAG_INT, _i, _EN)
#define BMI160_FIFO_SENSOR_EN(_sensor) \
	((_sensor) == MOTIONSENSE_TYPE_ACCEL ? BMI160_FIFO_ACC_EN : \
	  ((_sensor) == MOTIONSENSE_TYPE_GYRO ? BMI160_FIFO_GYR_EN : \
	   BMI160_FIFO_MAG_EN))

#define BMI160_MAG_IF_0        0x4b
#define BMI160_MAG_I2C_ADDRESS BMI160_MAG_IF_0
{'fraction_non_alphanumeric': 0.07398835822988989, 'fraction_numerical': 0.125745143418192, 'mean_word_length': 3.190420217455187, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '740440', 'n_tokens_mistral': 7185, 'n_tokens_neox': 5772, 'n_words': 1240}