diff options
author | Kevin K Wong <kevin.k.wong@intel.com> | 2016-03-30 16:42:40 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-03-31 21:35:56 -0700 |
commit | 6711629163f23a98099d8c6d37f6cdb1ef56ca52 (patch) | |
tree | 9529c236985d9ad64d23c4d0b1b8328d1be81b8f | |
parent | 59c03bc4c644b0f0bbf3c6807a97755b7509b319 (diff) | |
download | chrome-ec-6711629163f23a98099d8c6d37f6cdb1ef56ca52.tar.gz |
sensor: update sensor driver to use I2C port from motion_sensor_t
this allow motion sensor devices to be locate on different I2C port
BUG=none
BRANCH=none
TEST=make buildall
Change-Id: Ia7ba2f5729ebb19561768ec87fdb267e79aafb6a
Signed-off-by: Kevin K Wong <kevin.k.wong@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/334269
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | board/glados/board.c | 3 | ||||
-rw-r--r-- | board/kunimitsu/board.c | 3 | ||||
-rw-r--r-- | board/lars/board.c | 2 | ||||
-rw-r--r-- | board/oak/board.c | 3 | ||||
-rw-r--r-- | board/ryu/board.c | 4 | ||||
-rw-r--r-- | board/samus/board.c | 3 | ||||
-rw-r--r-- | board/strago/board.c | 2 | ||||
-rw-r--r-- | board/wheatley/board.c | 3 | ||||
-rw-r--r-- | driver/accel_kionix.c | 37 | ||||
-rw-r--r-- | driver/accelgyro_bmi160.c | 197 | ||||
-rw-r--r-- | driver/accelgyro_bmi160.h | 5 | ||||
-rw-r--r-- | driver/accelgyro_lsm6ds0.c | 38 | ||||
-rw-r--r-- | driver/als_si114x.c | 66 | ||||
-rw-r--r-- | driver/gyro_l3gd20h.c | 46 | ||||
-rw-r--r-- | driver/mag_bmm150.c | 30 | ||||
-rw-r--r-- | include/motion_sense.h | 4 | ||||
-rw-r--r-- | test/motion_lid.c | 2 |
17 files changed, 251 insertions, 197 deletions
diff --git a/board/glados/board.c b/board/glados/board.c index 37e00dbc06..892d5ed425 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -502,6 +502,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .rot_standard_ref = NULL, /* Identity matrix. */ .default_range = 2, /* g, enough for laptop. */ @@ -537,6 +538,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .default_range = 1000, /* dps */ .rot_standard_ref = NULL, /* Identity Matrix. */ @@ -572,6 +574,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_lid_mutex, .drv_data = &g_kx022_data, + .port = I2C_PORT_ACCEL, .addr = KX022_ADDR1, .rot_standard_ref = NULL, /* Identity matrix. */ .default_range = 2, /* g, enough for laptop. */ diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c index f092b86b63..1a1072c909 100644 --- a/board/kunimitsu/board.c +++ b/board/kunimitsu/board.c @@ -233,6 +233,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[0], .drv_data = &g_kxcj9_data[0], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR1, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -267,6 +268,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[1], .drv_data = &g_kxcj9_data[1], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR0, .rot_standard_ref = &lid_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -302,6 +304,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &l3gd20h_drv, .mutex = &g_l3gd20h_mutex, .drv_data = &g_l3gd20h_data, + .port = I2C_PORT_GYRO, .addr = L3GD20_ADDR1, .rot_standard_ref = NULL, .default_range = 2000, /* DPS */ diff --git a/board/lars/board.c b/board/lars/board.c index 45ff877a7d..ec06604c56 100644 --- a/board/lars/board.c +++ b/board/lars/board.c @@ -203,6 +203,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[0], .drv_data = &g_kxcj9_data[0], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR1, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -237,6 +238,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[1], .drv_data = &g_kxcj9_data[1], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR0, .rot_standard_ref = &lid_standard_ref, .default_range = 2, /* g, enough for laptop. */ diff --git a/board/oak/board.c b/board/oak/board.c index 420f423aec..4ab2c5c217 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -675,6 +675,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = 1, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -710,6 +711,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = 1, .default_range = 1000, /* dps */ .rot_standard_ref = NULL, /* Identity Matrix. */ @@ -746,6 +748,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_lid_mutex, .drv_data = &g_kx022_data, + .port = I2C_PORT_ACCEL, .addr = KX022_ADDR1, .rot_standard_ref = NULL, /* Identity matrix. */ .default_range = 2, /* g, enough for laptop. */ diff --git a/board/ryu/board.c b/board/ryu/board.c index a6712aa21b..aa59a6778a 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -298,6 +298,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .rot_standard_ref = &accelgyro_standard_ref, .default_range = 8, /* g, use hifi requirements */ @@ -332,6 +333,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .default_range = 1000, /* dps, use hifi requirement */ .rot_standard_ref = &accelgyro_standard_ref, @@ -366,6 +368,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .rot_standard_ref = &mag_standard_ref, .default_range = 1 << 11, /* 16LSB / uT, fixed */ @@ -434,6 +437,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &si114x_drv, .mutex = &g_mutex, .drv_data = &g_si114x_data, + .port = I2C_PORT_ALS, .addr = SI114X_ADDR, .rot_standard_ref = NULL, .default_range = 7630, /* Upon testing at desk */ diff --git a/board/samus/board.c b/board/samus/board.c index 84cadf1042..5257899ecc 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -309,6 +309,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &lsm6ds0_drv, .mutex = &g_base_mutex, .drv_data = &g_saved_data[0], + .port = I2C_PORT_ACCEL, .addr = LSM6DS0_ADDR1, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -343,6 +344,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_lid_mutex, .drv_data = &g_kxcj9_data, + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR0, .rot_standard_ref = &lid_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -377,6 +379,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &lsm6ds0_drv, .mutex = &g_base_mutex, .drv_data = &g_saved_data[1], + .port = I2C_PORT_ACCEL, .addr = LSM6DS0_ADDR1, .rot_standard_ref = NULL, .default_range = 2000, /* g, enough for laptop. */ diff --git a/board/strago/board.c b/board/strago/board.c index 6f49040a9f..fb40fb9a18 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -220,6 +220,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[0], .drv_data = &g_kxcj9_data[0], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR1, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -254,6 +255,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_kxcj9_mutex[1], .drv_data = &g_kxcj9_data[1], + .port = I2C_PORT_ACCEL, .addr = KXCJ9_ADDR0, .rot_standard_ref = &lid_standard_ref, .default_range = 2, /* g, enough for laptop. */ diff --git a/board/wheatley/board.c b/board/wheatley/board.c index 987bc6db6d..a276d4344d 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -476,6 +476,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL .addr = BMI160_ADDR0, .rot_standard_ref = NULL, /* Identity matrix. */ .default_range = 2, /* g, enough for laptop. */ @@ -511,6 +512,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_base_mutex, .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, .addr = BMI160_ADDR0, .default_range = 1000, /* dps */ .rot_standard_ref = NULL, /* Identity Matrix. */ @@ -546,6 +548,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &kionix_accel_drv, .mutex = &g_lid_mutex, .drv_data = &g_kx022_data, + .port = I2C_PORT_ACCEL, .addr = KX022_ADDR1, .rot_standard_ref = NULL, /* Identity matrix. */ .default_range = 2, /* g, enough for laptop. */ diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c index 8d86a5bbce..0a3754b4dd 100644 --- a/driver/accel_kionix.c +++ b/driver/accel_kionix.c @@ -125,17 +125,18 @@ static int find_param_index(const int eng_val, const int round_up, /** * Read register from accelerometer. */ -static int raw_read8(const int addr, const int reg, int *data_ptr) +static int raw_read8(const int port, const int addr, const int reg, + int *data_ptr) { - return i2c_read8(I2C_PORT_ACCEL, addr, reg, data_ptr); + return i2c_read8(port, addr, reg, data_ptr); } /** * Write register from accelerometer. */ -static int raw_write8(const int addr, const int reg, int data) +static int raw_write8(const int port, const int addr, const int reg, int data) { - return i2c_write8(I2C_PORT_ACCEL, addr, reg, data); + return i2c_write8(port, addr, reg, data); } /** @@ -162,13 +163,13 @@ static int disable_sensor(const struct motion_sensor_t *s, int *reg_val) * so that we can restore it later. */ for (i = 0; i < SENSOR_ENABLE_ATTEMPTS; i++) { - ret = raw_read8(s->addr, reg, reg_val); + ret = raw_read8(s->port, s->addr, reg, reg_val); if (ret != EC_SUCCESS) continue; *reg_val &= ~pc1_field; - ret = raw_write8(s->addr, reg, *reg_val); + ret = raw_write8(s->port, s->addr, reg, *reg_val); if (ret == EC_SUCCESS) return EC_SUCCESS; } @@ -194,12 +195,12 @@ static int enable_sensor(const struct motion_sensor_t *s, int reg_val) pc1_field = KIONIX_PC1_FIELD(data->variant); for (i = 0; i < SENSOR_ENABLE_ATTEMPTS; i++) { - ret = raw_read8(s->addr, reg, ®_val); + ret = raw_read8(s->port, s->addr, reg, ®_val); if (ret != EC_SUCCESS) continue; /* Enable accelerometer based on reg_val value. */ - ret = raw_write8(s->addr, reg, + ret = raw_write8(s->port, s->addr, reg, reg_val | pc1_field); /* On first success, we are done. */ @@ -230,7 +231,7 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd) /* Determine new value of control reg and attempt to write it. */ reg_val_new = (reg_val & ~range_field) | range_val; - ret = raw_write8(s->addr, reg, reg_val_new); + ret = raw_write8(s->port, s->addr, reg, reg_val_new); /* If successfully written, then save the range. */ if (ret == EC_SUCCESS) { @@ -274,7 +275,7 @@ static int set_resolution(const struct motion_sensor_t *s, int res, int rnd) /* Determine new value of the control reg and attempt to write it. */ reg_val_new = (reg_val & ~res_field) | res_val; - ret = raw_write8(s->addr, reg, reg_val_new); + ret = raw_write8(s->port, s->addr, reg, reg_val_new); /* If successfully written, then save the range. */ if (ret == EC_SUCCESS) { @@ -318,14 +319,14 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd) } /* Determine the new value of control reg and attempt to write it. */ - ret = raw_read8(s->addr, reg, &odr_reg_val); + ret = raw_read8(s->port, s->addr, reg, &odr_reg_val); if (ret != EC_SUCCESS) { mutex_unlock(s->mutex); return ret; } odr_val_new = (odr_reg_val & ~odr_field) | odr_val; /* Set output data rate. */ - ret = raw_write8(s->addr, reg, odr_val_new); + ret = raw_write8(s->port, s->addr, reg, odr_val_new); /* If successfully written, then save the new data rate. */ if (ret == EC_SUCCESS) @@ -377,10 +378,10 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) /* Read 6 bytes starting at XOUT_L. */ reg = KIONIX_XOUT_L(data->variant); mutex_lock(s->mutex); - i2c_lock(I2C_PORT_ACCEL, 1); - ret = i2c_xfer(I2C_PORT_ACCEL, s->addr, ®, 1, acc, 6, + i2c_lock(s->port, 1); + ret = i2c_xfer(s->port, s->addr, ®, 1, acc, 6, I2C_XFER_SINGLE); - i2c_lock(I2C_PORT_ACCEL, 0); + i2c_lock(s->port, 0); mutex_unlock(s->mutex); if (ret != EC_SUCCESS) @@ -439,13 +440,13 @@ static int init(const struct motion_sensor_t *s) mutex_unlock(s->mutex); return ret; } - ret = raw_read8(s->addr, reg, &val); + ret = raw_read8(s->port, s->addr, reg, &val); if (ret != EC_SUCCESS) { mutex_unlock(s->mutex); return ret; } val |= reset_field; - ret = raw_write8(s->addr, reg, val); + ret = raw_write8(s->port, s->addr, reg, val); if (ret != EC_SUCCESS) { mutex_unlock(s->mutex); return ret; @@ -456,7 +457,7 @@ static int init(const struct motion_sensor_t *s) do { msleep(1); - ret = raw_read8(s->addr, reg, &val); + ret = raw_read8(s->port, s->addr, reg, &val); if (ret != EC_SUCCESS) { mutex_unlock(s->mutex); return ret; diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index a9b869f02a..0cc192aec2 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -128,8 +128,8 @@ static int get_engineering_val(const int reg_val, } #ifdef CONFIG_SPI_ACCEL_PORT -static inline int spi_raw_read(const int addr, const uint8_t reg, uint8_t *data, - const int len) +static inline int spi_raw_read(const int addr, const uint8_t reg, + uint8_t *data, const int len) { uint8_t cmd = 0x80 | reg; @@ -139,7 +139,8 @@ static inline int spi_raw_read(const int addr, const uint8_t reg, uint8_t *data, /** * Read 8bit register from accelerometer. */ -static int raw_read8(const int addr, const uint8_t reg, int *data_ptr) +static int raw_read8(const int port, const int addr, const uint8_t reg, + int *data_ptr) { int rv = -EC_ERROR_PARAM1; @@ -152,7 +153,7 @@ static int raw_read8(const int addr, const uint8_t reg, int *data_ptr) #endif } else { #ifdef I2C_PORT_ACCEL - rv = i2c_read8(I2C_PORT_ACCEL, BMI160_I2C_ADDRESS(addr), + rv = i2c_read8(port, BMI160_I2C_ADDRESS(addr), reg, data_ptr); #endif } @@ -162,7 +163,8 @@ static int raw_read8(const int addr, const uint8_t reg, int *data_ptr) /** * Write 8bit register from accelerometer. */ -static int raw_write8(const int addr, const uint8_t reg, int data) +static int raw_write8(const int port, const int addr, const uint8_t reg, + int data) { int rv = -EC_ERROR_PARAM1; @@ -174,7 +176,7 @@ static int raw_write8(const int addr, const uint8_t reg, int data) #endif } else { #ifdef I2C_PORT_ACCEL - rv = i2c_write8(I2C_PORT_ACCEL, BMI160_I2C_ADDRESS(addr), + rv = i2c_write8(port, BMI160_I2C_ADDRESS(addr), reg, data); #endif } @@ -192,7 +194,8 @@ static int raw_write8(const int addr, const uint8_t reg, int data) /** * Read 32bit register from accelerometer. */ -static int raw_read32(const int addr, const uint8_t reg, int *data_ptr) +static int raw_read32(const int port, const int addr, const uint8_t reg, + int *data_ptr) { int rv = -EC_ERROR_PARAM1; if (BMI160_IS_SPI(addr)) { @@ -202,7 +205,7 @@ static int raw_read32(const int addr, const uint8_t reg, int *data_ptr) #endif } else { #ifdef I2C_PORT_ACCEL - rv = i2c_read32(I2C_PORT_ACCEL, BMI160_I2C_ADDRESS(addr), + rv = i2c_read32(port, BMI160_I2C_ADDRESS(addr), reg, data_ptr); #endif } @@ -213,7 +216,7 @@ static int raw_read32(const int addr, const uint8_t reg, int *data_ptr) /** * Read n bytes from accelerometer. */ -static int raw_read_n(const int addr, const uint8_t reg, +static int raw_read_n(const int port, const int addr, const uint8_t reg, uint8_t *data_ptr, const int len) { int rv = -EC_ERROR_PARAM1; @@ -224,10 +227,10 @@ static int raw_read_n(const int addr, const uint8_t reg, #endif } else { #ifdef I2C_PORT_ACCEL - i2c_lock(I2C_PORT_ACCEL, 1); - rv = i2c_xfer(I2C_PORT_ACCEL, BMI160_I2C_ADDRESS(addr), ®, 1, + i2c_lock(port, 1); + rv = i2c_xfer(port, BMI160_I2C_ADDRESS(addr), ®, 1, data_ptr, len, I2C_XFER_SINGLE); - i2c_lock(I2C_PORT_ACCEL, 0); + i2c_lock(port, 0); #endif } return rv; @@ -240,10 +243,11 @@ static int raw_read_n(const int addr, const uint8_t reg, * 1: manual access, we can issue i2c to the compass * 0: data access: BMI160 gather data periodically from the compass. */ -static int bmm150_mag_access_ctrl(const int addr, const int enable) +static int bmm150_mag_access_ctrl(const int port, const int addr, + const int enable) { int mag_if_ctrl; - raw_read8(addr, BMI160_MAG_IF_1, &mag_if_ctrl); + raw_read8(port, addr, BMI160_MAG_IF_1, &mag_if_ctrl); if (enable) { mag_if_ctrl |= BMI160_MAG_MANUAL_EN; mag_if_ctrl &= ~BMI160_MAG_READ_BURST_MASK; @@ -253,28 +257,29 @@ static int bmm150_mag_access_ctrl(const int addr, const int enable) mag_if_ctrl &= ~BMI160_MAG_READ_BURST_MASK; mag_if_ctrl |= BMI160_MAG_READ_BURST_8; } - return raw_write8(addr, BMI160_MAG_IF_1, mag_if_ctrl); + return raw_write8(port, addr, BMI160_MAG_IF_1, mag_if_ctrl); } /** * Read register from compass. * Assuming we are in manual access mode, read compass i2c register. */ -int raw_mag_read8(const int addr, const uint8_t reg, int *data_ptr) +int raw_mag_read8(const int port, const int addr, const uint8_t reg, + int *data_ptr) { /* Only read 1 bytes */ - raw_write8(addr, BMI160_MAG_I2C_READ_ADDR, reg); - return raw_read8(addr, BMI160_MAG_I2C_READ_DATA, data_ptr); + raw_write8(port, addr, BMI160_MAG_I2C_READ_ADDR, reg); + return raw_read8(port, addr, BMI160_MAG_I2C_READ_DATA, data_ptr); } /** * Write register from compass. * Assuming we are in manual access mode, write to compass i2c register. */ -int raw_mag_write8(const int addr, const uint8_t reg, int data) +int raw_mag_write8(const int port, const int addr, const uint8_t reg, int data) { - raw_write8(addr, BMI160_MAG_I2C_WRITE_DATA, data); - return raw_write8(addr, BMI160_MAG_I2C_WRITE_ADDR, reg); + raw_write8(port, addr, BMI160_MAG_I2C_WRITE_DATA, data); + return raw_write8(port, addr, BMI160_MAG_I2C_WRITE_ADDR, reg); } #endif @@ -286,17 +291,17 @@ static int enable_fifo(const struct motion_sensor_t *s, int enable) if (enable) { /* FIFO start collecting events */ - ret = raw_read8(s->addr, BMI160_FIFO_CONFIG_1, &val); + ret = raw_read8(s->port, s->addr, BMI160_FIFO_CONFIG_1, &val); val |= BMI160_FIFO_SENSOR_EN(s->type); - ret = raw_write8(s->addr, BMI160_FIFO_CONFIG_1, val); + ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1, val); if (ret == EC_SUCCESS) data->flags |= 1 << (s->type + BMI160_FIFO_FLAG_OFFSET); } else { /* FIFO stop collecting events */ - ret = raw_read8(s->addr, BMI160_FIFO_CONFIG_1, &val); + ret = raw_read8(s->port, s->addr, BMI160_FIFO_CONFIG_1, &val); val &= ~BMI160_FIFO_SENSOR_EN(s->type); - ret = raw_write8(s->addr, BMI160_FIFO_CONFIG_1, val); + ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1, val); if (ret == EC_SUCCESS) data->flags &= ~(1 << (s->type + BMI160_FIFO_FLAG_OFFSET)); @@ -323,7 +328,7 @@ static int set_range(const struct motion_sensor_t *s, ranges = get_range_table(s->type, &range_tbl_size); reg_val = get_reg_val(range, rnd, ranges, range_tbl_size); - ret = raw_write8(s->addr, ctrl_reg, reg_val); + ret = raw_write8(s->port, s->addr, ctrl_reg, reg_val); /* Now that we have set the range, update the driver's value. */ if (ret == EC_SUCCESS) data->range = get_engineering_val(reg_val, ranges, @@ -368,7 +373,7 @@ static int set_data_rate(const struct motion_sensor_t *s, enable_fifo(s, 0); #endif /* go to suspend mode */ - ret = raw_write8(s->addr, BMI160_CMD_REG, + ret = raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_MODE_SUSPEND(s->type)); msleep(3); data->odr = 0; @@ -379,7 +384,7 @@ static int set_data_rate(const struct motion_sensor_t *s, return ret; } else if (data->odr == 0) { /* back from suspend mode. */ - ret = raw_write8(s->addr, BMI160_CMD_REG, + ret = raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_MODE_NORMAL(s->type)); msleep(wakeup_time[s->type]); } @@ -431,12 +436,12 @@ static int set_data_rate(const struct motion_sensor_t *s, */ mutex_lock(s->mutex); - ret = raw_read8(s->addr, ctrl_reg, &val); + ret = raw_read8(s->port, s->addr, ctrl_reg, &val); if (ret != EC_SUCCESS) goto accel_cleanup; val = (val & ~BMI160_ODR_MASK) | reg_val; - ret = raw_write8(s->addr, ctrl_reg, val); + ret = raw_write8(s->port, s->addr, ctrl_reg, val); if (ret != EC_SUCCESS) goto accel_cleanup; @@ -493,7 +498,8 @@ static int get_offset(const struct motion_sensor_t *s, * range selected for the accelerometer. */ for (i = X; i <= Z; i++) { - raw_read8(s->addr, BMI160_OFFSET_ACC70 + i, &val); + raw_read8(s->port, s->addr, BMI160_OFFSET_ACC70 + i, + &val); if (val > 0x7f) val = -256 + val; v[i] = val * BMI160_OFFSET_ACC_MULTI_MG / @@ -502,7 +508,7 @@ static int get_offset(const struct motion_sensor_t *s, break; case MOTIONSENSE_TYPE_GYRO: /* Read the MSB first */ - raw_read8(s->addr, BMI160_OFFSET_EN_GYR98, &val98); + raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val98); /* * The offset of the gyroscope off_gyr_[xyz] is a 10 bit * two-complement number in units of 0.061 °/s. @@ -510,7 +516,8 @@ static int get_offset(const struct motion_sensor_t *s, * -31.25 °/s to +31.25 °/s */ for (i = X; i <= Z; i++) { - raw_read8(s->addr, BMI160_OFFSET_GYR70 + i, &val); + raw_read8(s->port, s->addr, BMI160_OFFSET_GYR70 + i, + &val); val |= ((val98 >> (2 * i)) & 0x3) << 8; if (val > 0x1ff) val = -1024 + val; @@ -545,7 +552,7 @@ static int set_offset(const struct motion_sensor_t *s, rotate_inv(v, *s->rot_standard_ref, v); - ret = raw_read8(s->addr, BMI160_OFFSET_EN_GYR98, &val98); + ret = raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val98); if (ret != 0) return ret; @@ -560,9 +567,10 @@ static int set_offset(const struct motion_sensor_t *s, val = -128; if (val < 0) val = 256 + val; - raw_write8(s->addr, BMI160_OFFSET_ACC70 + i, val); + raw_write8(s->port, s->addr, BMI160_OFFSET_ACC70 + i, + val); } - ret = raw_write8(s->addr, BMI160_OFFSET_EN_GYR98, + ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, val98 | BMI160_OFFSET_ACC_EN); break; case MOTIONSENSE_TYPE_GYRO: @@ -575,12 +583,12 @@ static int set_offset(const struct motion_sensor_t *s, val = -512; if (val < 0) val = 1024 + val; - raw_write8(s->addr, BMI160_OFFSET_GYR70 + i, + raw_write8(s->port, s->addr, BMI160_OFFSET_GYR70 + i, val & 0xFF); val98 &= ~(0x3 << (2 * i)); val98 |= (val >> 8) << (2 * i); } - ret = raw_write8(s->addr, BMI160_OFFSET_EN_GYR98, + ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, val98 | BMI160_OFFSET_GYRO_EN); break; #ifdef CONFIG_MAG_BMI160_BMM150 @@ -622,23 +630,25 @@ int perform_calib(const struct motion_sensor_t *s) ret = EC_RES_INVALID_PARAM; goto end_perform_calib; } - ret = raw_write8(s->addr, BMI160_FOC_CONF, val); - ret = raw_write8(s->addr, BMI160_CMD_REG, BMI160_CMD_START_FOC); + ret = raw_write8(s->port, s->addr, BMI160_FOC_CONF, val); + ret = raw_write8(s->port, s->addr, BMI160_CMD_REG, + BMI160_CMD_START_FOC); do { if (timeout > 400) { ret = EC_RES_TIMEOUT; goto end_perform_calib; } msleep(50); - ret = raw_read8(s->addr, BMI160_STATUS, &status); + ret = raw_read8(s->port, s->addr, BMI160_STATUS, &status); if (ret != EC_SUCCESS) goto end_perform_calib; timeout += 50; } while ((status & BMI160_FOC_RDY) == 0); /* Calibration is successful, and loaded, use the result */ - ret = raw_read8(s->addr, BMI160_OFFSET_EN_GYR98, &val); - ret = raw_write8(s->addr, BMI160_OFFSET_EN_GYR98, val | en_flag); + ret = raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val); + ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, + val | en_flag); end_perform_calib: set_data_rate(s, rate, 0); return ret; @@ -676,12 +686,12 @@ int manage_activity(const struct motion_sensor_t *s, #ifdef CONFIG_GESTURE_SIGMO case MOTIONSENSE_ACTIVITY_SIG_MOTION: { int tmp; - ret = raw_read8(s->addr, BMI160_INT_EN_0, &tmp); + ret = raw_read8(s->port, s->addr, BMI160_INT_EN_0, &tmp); if (ret) return ret; if (enable) { /* We should use parameters from caller */ - raw_write8(s->addr, BMI160_INT_MOTION_3, + raw_write8(s->port, s->addr, BMI160_INT_MOTION_3, BMI160_MOTION_PROOF_TIME( CONFIG_GESTURE_SIGMO_PROOF_MS) << BMI160_MOTION_PROOF_OFF | @@ -689,7 +699,7 @@ int manage_activity(const struct motion_sensor_t *s, CONFIG_GESTURE_SIGMO_SKIP_MS) << BMI160_MOTION_SKIP_OFF | BMI160_MOTION_SIG_MOT_SEL); - raw_write8(s->addr, BMI160_INT_MOTION_1, + raw_write8(s->port, s->addr, BMI160_INT_MOTION_1, BMI160_MOTION_TH(s, CONFIG_GESTURE_SIGMO_THRES_MG)); tmp |= BMI160_INT_ANYMO_X_EN | @@ -700,7 +710,7 @@ int manage_activity(const struct motion_sensor_t *s, BMI160_INT_ANYMO_Y_EN | BMI160_INT_ANYMO_Z_EN); } - ret = raw_write8(s->addr, BMI160_INT_EN_0, tmp); + ret = raw_write8(s->port, s->addr, BMI160_INT_EN_0, tmp); if (ret) ret = EC_RES_UNAVAILABLE; break; @@ -710,14 +720,14 @@ int manage_activity(const struct motion_sensor_t *s, case MOTIONSENSE_ACTIVITY_DOUBLE_TAP: { int tmp; /* Set double tap interrupt */ - ret = raw_read8(s->addr, BMI160_INT_EN_0, &tmp); + ret = raw_read8(s->port, s->addr, BMI160_INT_EN_0, &tmp); if (ret) return ret; if (enable) tmp |= BMI160_INT_D_TAP_EN; else tmp &= ~BMI160_INT_D_TAP_EN; - ret = raw_write8(s->addr, BMI160_INT_EN_0, tmp); + ret = raw_write8(s->port, s->addr, BMI160_INT_EN_0, tmp); if (ret) ret = EC_RES_UNAVAILABLE; break; @@ -772,14 +782,14 @@ static int config_interrupt(const struct motion_sensor_t *s) return EC_SUCCESS; mutex_lock(s->mutex); - raw_write8(s->addr, BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH); + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH); msleep(30); - raw_write8(s->addr, BMI160_CMD_REG, BMI160_CMD_INT_RESET); + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_INT_RESET); #ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP - raw_write8(s->addr, BMI160_INT_TAP_0, + raw_write8(s->port, s->addr, BMI160_INT_TAP_0, BMI160_TAP_TH(s, CONFIG_GESTURE_TAP_MAX_INTERSTICE_T)); - ret = raw_write8(s->addr, BMI160_INT_TAP_1, + ret = raw_write8(s->port, s->addr, BMI160_INT_TAP_1, BMI160_TAP_TH(s, CONFIG_GESTURE_TAP_THRES_MG)); #endif /* @@ -787,11 +797,11 @@ static int config_interrupt(const struct motion_sensor_t *s) * Set a 5ms latch to be sure the EC can read the interrupt register * properly, even when it is running more slowly. */ - ret = raw_write8(s->addr, BMI160_INT_LATCH, + ret = raw_write8(s->port, s->addr, BMI160_INT_LATCH, BMI160_INT2_INPUT_EN | BMI160_LATCH_5MS); /* configure int1 as an interupt */ - ret = raw_write8(s->addr, BMI160_INT_OUT_CTRL, + ret = raw_write8(s->port, s->addr, BMI160_INT_OUT_CTRL, BMI160_INT_CTRL(1, OUTPUT_EN)); /* Map activity interrupt to int 1 */ @@ -802,26 +812,26 @@ static int config_interrupt(const struct motion_sensor_t *s) #ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP tmp |= BMI160_INT_D_TAP; #endif - ret = raw_write8(s->addr, BMI160_INT_MAP_REG(1), tmp); + ret = raw_write8(s->port, s->addr, BMI160_INT_MAP_REG(1), tmp); #ifdef CONFIG_ACCEL_FIFO /* map fifo water mark to int 1 */ - ret = raw_write8(s->addr, BMI160_INT_FIFO_MAP, + ret = raw_write8(s->port, s->addr, BMI160_INT_FIFO_MAP, BMI160_INT_MAP(1, FWM) | BMI160_INT_MAP(1, FFULL)); /* configure fifo watermark at 50% */ - ret = raw_write8(s->addr, BMI160_FIFO_CONFIG_0, + ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_0, 512 / sizeof(uint32_t)); - ret = raw_write8(s->addr, BMI160_FIFO_CONFIG_1, + ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1, BMI160_FIFO_TAG_INT1_EN | BMI160_FIFO_TAG_INT2_EN | BMI160_FIFO_HEADER_EN); /* Set fifo*/ - ret = raw_read8(s->addr, BMI160_INT_EN_1, &tmp); + ret = raw_read8(s->port, s->addr, BMI160_INT_EN_1, &tmp); tmp |= BMI160_INT_FWM_EN | BMI160_INT_FFUL_EN; - ret = raw_write8(s->addr, BMI160_INT_EN_1, tmp); + ret = raw_write8(s->port, s->addr, BMI160_INT_EN_1, tmp); #endif mutex_unlock(s->mutex); return ret; @@ -842,7 +852,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) (!(*event & CONFIG_ACCELGYRO_BMI160_INT_EVENT))) return EC_ERROR_NOT_HANDLED; - raw_read32(s->addr, BMI160_INT_STATUS_0, &interrupt); + raw_read32(s->port, s->addr, BMI160_INT_STATUS_0, &interrupt); #ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP if (interrupt & BMI160_D_TAP_INT) @@ -955,12 +965,12 @@ static int load_fifo(struct motion_sensor_t *s) * Flush potential left over: * When sensor is resumed, we won't read old data. */ - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH); return EC_SUCCESS; } - raw_read_n(s->addr, BMI160_FIFO_DATA, bmi160_buffer, + raw_read_n(s->port, s->addr, BMI160_FIFO_DATA, bmi160_buffer, sizeof(bmi160_buffer)); beginning = *(uint32_t *)bmi160_buffer; /* @@ -1004,7 +1014,8 @@ static int load_fifo(struct motion_sensor_t *s) default: CPRINTS("Unknown header: 0x%02x @ %d", hdr, bp - bmi160_buffer); - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, + BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH); done = 1; } @@ -1045,7 +1056,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) uint8_t data[6]; int ret, status = 0; - ret = raw_read8(s->addr, BMI160_STATUS, &status); + ret = raw_read8(s->port, s->addr, BMI160_STATUS, &status); if (ret != EC_SUCCESS) return ret; @@ -1061,7 +1072,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) } /* Read 6 bytes starting at xyz_reg */ - raw_read_n(s->addr, get_xyz_reg(s->type), data, 6); + raw_read_n(s->port, s->addr, get_xyz_reg(s->type), data, 6); if (ret != EC_SUCCESS) { CPRINTF("[%T %s type:0x%X RD XYZ Error %d]", @@ -1076,21 +1087,21 @@ static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; - ret = raw_read8(s->addr, BMI160_CHIP_ID, &tmp); + ret = raw_read8(s->port, s->addr, BMI160_CHIP_ID, &tmp); if (ret) return EC_ERROR_UNKNOWN; if (tmp != BMI160_CHIP_ID_MAJOR) { /* The device may be lock on paging mode. Try to unlock it. */ - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B0); - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B1); - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B2); - raw_write8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, BMI160_CMD_PAGING_EN); - raw_write8(s->addr, BMI160_CMD_EXT_MODE_ADDR, 0); + raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, 0); return EC_ERROR_ACCESS_DENIED; } @@ -1099,7 +1110,7 @@ static int init(const struct motion_sensor_t *s) struct bmi160_drv_data_t *data = BMI160_GET_DATA(s); /* Reset the chip to be in a good state */ - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_SOFT_RESET); msleep(30); data->flags &= ~(BMI160_FLAG_SEC_I2C_ENABLED | @@ -1118,10 +1129,10 @@ static int init(const struct motion_sensor_t *s) #endif #endif /* To avoid gyro wakeup */ - raw_write8(s->addr, BMI160_PMU_TRIGGER, 0); + raw_write8(s->port, s->addr, BMI160_PMU_TRIGGER, 0); } - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_MODE_NORMAL(s->type)); msleep(wakeup_time[s->type]); @@ -1138,48 +1149,48 @@ static int init(const struct motion_sensor_t *s) * * Magic command sequences */ - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B0); - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B1); - raw_write8(s->addr, BMI160_CMD_REG, + raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B2); /* * Change the register page to target mode, to change * the internal pull ups of the secondary interface. */ - raw_read8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg); - raw_write8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, ext_page_reg | BMI160_CMD_TARGET_PAGE); - raw_read8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg); - raw_write8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, ext_page_reg | BMI160_CMD_PAGING_EN); - raw_read8(s->addr, BMI160_COM_C_TRIM_ADDR, + raw_read8(s->port, s->addr, BMI160_COM_C_TRIM_ADDR, &pullup_reg); - raw_write8(s->addr, BMI160_COM_C_TRIM_ADDR, + raw_write8(s->port, s->addr, BMI160_COM_C_TRIM_ADDR, pullup_reg | BMI160_COM_C_TRIM); - raw_read8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg); - raw_write8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, ext_page_reg & ~BMI160_CMD_TARGET_PAGE); - raw_read8(s->addr, BMI160_CMD_EXT_MODE_ADDR, + raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg); /* Set the i2c address of the compass */ - ret = raw_write8(s->addr, BMI160_MAG_IF_0, + ret = raw_write8(s->port, s->addr, BMI160_MAG_IF_0, BMM150_I2C_ADDRESS); /* Enable the secondary interface as I2C */ - ret = raw_write8(s->addr, BMI160_IF_CONF, + ret = raw_write8(s->port, s->addr, BMI160_IF_CONF, BMI160_IF_MODE_AUTO_I2C << BMI160_IF_MODE_OFF); data->flags |= BMI160_FLAG_SEC_I2C_ENABLED; } - bmm150_mag_access_ctrl(s->addr, 1); + bmm150_mag_access_ctrl(s->port, s->addr, 1); ret = bmm150_init(s); if (ret) @@ -1187,13 +1198,13 @@ static int init(const struct motion_sensor_t *s) return ret; /* Leave the address for reading the data */ - raw_write8(s->addr, BMI160_MAG_I2C_READ_ADDR, + raw_write8(s->port, s->addr, BMI160_MAG_I2C_READ_ADDR, BMM150_BASE_DATA); /* * Put back the secondary interface in normal mode. * BMI160 will poll based on the configure ODR. */ - bmm150_mag_access_ctrl(s->addr, 0); + bmm150_mag_access_ctrl(s->port, s->addr, 0); } #endif diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h index 4c98644691..7fb4af9e04 100644 --- a/driver/accelgyro_bmi160.h +++ b/driver/accelgyro_bmi160.h @@ -453,8 +453,9 @@ void bmi160_interrupt(enum gpio_signal signal); #ifdef CONFIG_MAG_BMI160_BMM150 /* Functions to access the compass through the accel/gyro. */ -int raw_mag_read8(const int addr, const uint8_t reg, int *data_ptr); -int raw_mag_write8(const int addr, const uint8_t reg, int data); +int raw_mag_read8(const int port, const int addr, const uint8_t reg, + int *data_ptr); +int raw_mag_write8(const int port, const int addr, const uint8_t reg, int data); #endif diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c index 62996825ac..7948e651ce 100644 --- a/driver/accelgyro_lsm6ds0.c +++ b/driver/accelgyro_lsm6ds0.c @@ -150,17 +150,19 @@ static int get_engineering_val(const int reg_val, /** * Read register from accelerometer. */ -static inline int raw_read8(const int addr, const int reg, int *data_ptr) +static inline int raw_read8(const int port, const int addr, const int reg, + int *data_ptr) { - return i2c_read8(I2C_PORT_ACCEL, addr, reg, data_ptr); + return i2c_read8(port, addr, reg, data_ptr); } /** * Write register from accelerometer. */ -static inline int raw_write8(const int addr, const int reg, int data) +static inline int raw_write8(const int port, const int addr, const int reg, + int data) { - return i2c_write8(I2C_PORT_ACCEL, addr, reg, data); + return i2c_write8(port, addr, reg, data); } static int set_range(const struct motion_sensor_t *s, @@ -183,12 +185,12 @@ static int set_range(const struct motion_sensor_t *s, */ mutex_lock(s->mutex); - ret = raw_read8(s->addr, ctrl_reg, &ctrl_val); + ret = raw_read8(s->port, s->addr, ctrl_reg, &ctrl_val); if (ret != EC_SUCCESS) goto accel_cleanup; ctrl_val = (ctrl_val & ~LSM6DS0_RANGE_MASK) | reg_val; - ret = raw_write8(s->addr, ctrl_reg, ctrl_val); + ret = raw_write8(s->port, s->addr, ctrl_reg, ctrl_val); /* Now that we have set the range, update the driver's value. */ if (ret == EC_SUCCESS) @@ -239,12 +241,12 @@ static int set_data_rate(const struct motion_sensor_t *s, */ mutex_lock(s->mutex); - ret = raw_read8(s->addr, ctrl_reg, &val); + ret = raw_read8(s->port, s->addr, ctrl_reg, &val); if (ret != EC_SUCCESS) goto accel_cleanup; val = (val & ~LSM6DS0_ODR_MASK) | reg_val; - ret = raw_write8(s->addr, ctrl_reg, val); + ret = raw_write8(s->port, s->addr, ctrl_reg, val); /* Now that we have set the odr, update the driver's value. */ if (ret == EC_SUCCESS) @@ -259,14 +261,14 @@ static int set_data_rate(const struct motion_sensor_t *s, * Table 48 Gyroscope high-pass filter cutoff frequency */ if (MOTIONSENSE_TYPE_GYRO == s->type) { - ret = raw_read8(s->addr, LSM6DS0_CTRL_REG3_G, &val); + ret = raw_read8(s->port, s->addr, LSM6DS0_CTRL_REG3_G, &val); if (ret != EC_SUCCESS) goto accel_cleanup; val &= ~(0x3 << 4); /* clear bit [5:4] */ val = (rate > 119000) ? (val | (1<<7)) /* set high-power mode */ : (val & ~(1<<7)); /* set low-power mode */ - ret = raw_write8(s->addr, LSM6DS0_CTRL_REG3_G, val); + ret = raw_write8(s->port, s->addr, LSM6DS0_CTRL_REG3_G, val); } accel_cleanup: @@ -318,7 +320,7 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready) { int ret, tmp; - ret = raw_read8(s->addr, LSM6DS0_STATUS_REG, &tmp); + ret = raw_read8(s->port, s->addr, LSM6DS0_STATUS_REG, &tmp); if (ret != EC_SUCCESS) { CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type); @@ -358,10 +360,10 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) xyz_reg = get_xyz_reg(s->type); /* Read 6 bytes starting at xyz_reg */ - i2c_lock(I2C_PORT_ACCEL, 1); - ret = i2c_xfer(I2C_PORT_ACCEL, s->addr, + i2c_lock(s->port, 1); + ret = i2c_xfer(s->port, s->addr, &xyz_reg, 1, raw, 6, I2C_XFER_SINGLE); - i2c_lock(I2C_PORT_ACCEL, 0); + i2c_lock(s->port, 0); if (ret != EC_SUCCESS) { CPRINTF("[%T %s type:0x%X RD XYZ Error]", @@ -386,7 +388,7 @@ static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; - ret = raw_read8(s->addr, LSM6DS0_WHO_AM_I_REG, &tmp); + ret = raw_read8(s->port, s->addr, LSM6DS0_WHO_AM_I_REG, &tmp); if (ret) return EC_ERROR_UNKNOWN; @@ -408,20 +410,20 @@ static int init(const struct motion_sensor_t *s) if (MOTIONSENSE_TYPE_ACCEL == s->type) { mutex_lock(s->mutex); - ret = raw_read8(s->addr, LSM6DS0_CTRL_REG8, &tmp); + ret = raw_read8(s->port, s->addr, LSM6DS0_CTRL_REG8, &tmp); if (ret) { mutex_unlock(s->mutex); return EC_ERROR_UNKNOWN; } tmp |= (1 | LSM6DS0_BDU_ENABLE); - ret = raw_write8(s->addr, LSM6DS0_CTRL_REG8, tmp); + ret = raw_write8(s->port, s->addr, LSM6DS0_CTRL_REG8, tmp); mutex_unlock(s->mutex); if (ret) return EC_ERROR_UNKNOWN; /* Power Down Gyro */ - ret = raw_write8(s->addr, + ret = raw_write8(s->port, s->addr, LSM6DS0_CTRL_REG1_G, 0x0); if (ret) return EC_ERROR_UNKNOWN; diff --git a/driver/als_si114x.c b/driver/als_si114x.c index 5a64be92cd..b9c6e5ecc5 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -26,25 +26,28 @@ static int init(const struct motion_sensor_t *s); /** * Read 8bit register from device. */ -static inline int raw_read8(const int addr, const int reg, int *data_ptr) +static inline int raw_read8(const int port, const int addr, const int reg, + int *data_ptr) { - return i2c_read8(I2C_PORT_ALS, addr, reg, data_ptr); + return i2c_read8(port, addr, reg, data_ptr); } /** * Write 8bit register from device. */ -static inline int raw_write8(const int addr, const int reg, int data) +static inline int raw_write8(const int port, const int addr, const int reg, + int data) { - return i2c_write8(I2C_PORT_ALS, addr, reg, data); + return i2c_write8(port, addr, reg, data); } /** * Read 16bit register from device. */ -static inline int raw_read16(const int addr, const int reg, int *data_ptr) +static inline int raw_read16(const int port, const int addr, const int reg, + int *data_ptr) { - return i2c_read16(I2C_PORT_ALS, addr, reg, data_ptr); + return i2c_read16(port, addr, reg, data_ptr); } /* helper function to operate on parameter values: op can be query/set/or/and */ @@ -58,16 +61,17 @@ static int si114x_param_op(const struct motion_sensor_t *s, mutex_lock(s->mutex); if (op != SI114X_CMD_PARAM_QUERY) { - ret = raw_write8(s->addr, SI114X_REG_PARAM_WR, *value); + ret = raw_write8(s->port, s->addr, SI114X_REG_PARAM_WR, *value); if (ret != EC_SUCCESS) goto error; } - ret = raw_write8(s->addr, SI114X_REG_COMMAND, op | (param & 0x1F)); + ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, + op | (param & 0x1F)); if (ret != EC_SUCCESS) goto error; - ret = raw_read8(s->addr, SI114X_REG_PARAM_RD, value); + ret = raw_read8(s->port, s->addr, SI114X_REG_PARAM_RD, value); if (ret != EC_SUCCESS) goto error; @@ -91,7 +95,8 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb) /* Read ALX result */ for (i = 0; i < nb; i++) { - ret = raw_read16(s->addr, type_data->base_data_reg + i * 2, + ret = raw_read16(s->port, s->addr, + type_data->base_data_reg + i * 2, &val); if (ret) break; @@ -170,7 +175,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) if (!(*event & CONFIG_ALS_SI114X_INT_EVENT)) return EC_ERROR_NOT_HANDLED; - ret = raw_read8(s->addr, SI114X_REG_IRQ_STATUS, &val); + ret = raw_read8(s->port, s->addr, SI114X_REG_IRQ_STATUS, &val); if (ret) return ret; @@ -178,7 +183,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) return EC_ERROR_INVAL; /* clearing IRQ */ - ret = raw_write8(s->addr, SI114X_REG_IRQ_STATUS, + ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_STATUS, val & type_data->irq_flags); if (ret != EC_SUCCESS) CPRINTS("clearing irq failed"); @@ -190,7 +195,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) ret = si114x_read_results(s, 1); /* Fire pending requests */ if (data->state == SI114X_ALS_IN_PROGRESS_PS_PENDING) { - ret = raw_write8(s->addr, SI114X_REG_COMMAND, + ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, SI114X_CMD_PS_FORCE); data->state = SI114X_PS_IN_PROGRESS; } else { @@ -202,7 +207,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) /* Read PS results */ ret = si114x_read_results(s, SI114X_NUM_LEDS); if (data->state == SI114X_PS_IN_PROGRESS_ALS_PENDING) { - ret = raw_write8(s->addr, SI114X_REG_COMMAND, + ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, SI114X_CMD_ALS_FORCE); data->state = SI114X_ALS_IN_PROGRESS; } else { @@ -256,7 +261,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) CPRINTS("Invalid sensor type"); return EC_ERROR_INVAL; } - ret = raw_write8(s->addr, SI114X_REG_COMMAND, cmd); + ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, cmd); ret = EC_RES_IN_PROGRESS; break; case SI114X_ALS_IN_PROGRESS_PS_PENDING: @@ -279,7 +284,8 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) s->last_collection + SI114X_DENIED_THRESHOLD)) { int ret, val; - ret = raw_read8(s->addr, SI114X_REG_IRQ_STATUS, &val); + ret = raw_read8(s->port, s->addr, + SI114X_REG_IRQ_STATUS, &val); CPRINTS("%d stuck IRQ_STATUS 0x%02x - ret %d", s->name, val, ret); init(s); @@ -312,7 +318,7 @@ static int si114x_set_chlist(const struct motion_sensor_t *s) static int si114x_revisions(const struct motion_sensor_t *s) { int val; - int ret = raw_read8(s->addr, SI114X_REG_PART_ID, &val); + int ret = raw_read8(s->port, s->addr, SI114X_REG_PART_ID, &val); if (ret != EC_SUCCESS) return ret; @@ -321,7 +327,7 @@ static int si114x_revisions(const struct motion_sensor_t *s) return EC_ERROR_ACCESS_DENIED; } - ret = raw_read8(s->addr, SI114X_REG_SEQ_ID, &val); + ret = raw_read8(s->port, s->port, s->addr, SI114X_REG_SEQ_ID, &val); if (ret != EC_SUCCESS) return ret; @@ -337,60 +343,62 @@ static int si114x_initialize(const struct motion_sensor_t *s) int ret, val; /* send reset command */ - ret = raw_write8(s->addr, SI114X_REG_COMMAND, SI114X_CMD_RESET); + ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, + SI114X_CMD_RESET); if (ret != EC_SUCCESS) return ret; msleep(20); /* hardware key, magic value */ - ret = raw_write8(s->addr, SI114X_REG_HW_KEY, 0x17); + ret = raw_write8(s->port, s->addr, SI114X_REG_HW_KEY, 0x17); if (ret != EC_SUCCESS) return ret; msleep(20); /* interrupt configuration, interrupt output enable */ - ret = raw_write8(s->addr, SI114X_REG_INT_CFG, SI114X_INT_CFG_OE); + ret = raw_write8(s->port, s->addr, SI114X_REG_INT_CFG, + SI114X_INT_CFG_OE); if (ret != EC_SUCCESS) return ret; /* enable interrupt for certain activities */ - ret = raw_write8(s->addr, SI114X_REG_IRQ_ENABLE, + ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_ENABLE, SI114X_PS3_IE | SI114X_PS2_IE | SI114X_PS1_IE | SI114X_ALS_INT0_IE); if (ret != EC_SUCCESS) return ret; /* Only forced mode */ - ret = raw_write8(s->addr, SI114X_REG_MEAS_RATE, 0); + ret = raw_write8(s->port, s->addr, SI114X_REG_MEAS_RATE, 0); if (ret != EC_SUCCESS) return ret; /* measure ALS every time device wakes up */ - ret = raw_write8(s->addr, SI114X_REG_ALS_RATE, 0); + ret = raw_write8(s->port, s->addr, SI114X_REG_ALS_RATE, 0); if (ret != EC_SUCCESS) return ret; /* measure proximity every time device wakes up */ - ret = raw_write8(s->addr, SI114X_REG_PS_RATE, 0); + ret = raw_write8(s->port, s->addr, SI114X_REG_PS_RATE, 0); if (ret != EC_SUCCESS) return ret; /* set LED currents to maximum */ switch (SI114X_NUM_LEDS) { case 3: - ret = raw_write8(s->addr, + ret = raw_write8(s->port, s->addr, SI114X_REG_PS_LED3, 0x0f); if (ret != EC_SUCCESS) return ret; - ret = raw_write8(s->addr, + ret = raw_write8(s->port, s->addr, SI114X_REG_PS_LED21, 0xff); break; case 2: - ret = raw_write8(s->addr, + ret = raw_write8(s->port, s->addr, SI114X_REG_PS_LED21, 0xff); break; case 1: - ret = raw_write8(s->addr, + ret = raw_write8(s->port, s->addr, SI114X_REG_PS_LED21, 0x0f); break; } diff --git a/driver/gyro_l3gd20h.c b/driver/gyro_l3gd20h.c index 1137728463..5d1fd3e1e0 100644 --- a/driver/gyro_l3gd20h.c +++ b/driver/gyro_l3gd20h.c @@ -118,17 +118,19 @@ static int get_engineering_val(const int reg_val, /** * Read register from Gyrometer. */ -static inline int raw_read8(const int addr, const int reg, int *data_ptr) +static inline int raw_read8(const int port, const int addr, const int reg, + int *data_ptr) { - return i2c_read8(I2C_PORT_GYRO, addr, reg, data_ptr); + return i2c_read8(port, addr, reg, data_ptr); } /** * Write register from Gyrometer. */ -static inline int raw_write8(const int addr, const int reg, int data) +static inline int raw_write8(const int port, const int addr, const int reg, + int data) { - return i2c_write8(I2C_PORT_GYRO, addr, reg, data); + return i2c_write8(port, addr, reg, data); } static int set_range(const struct motion_sensor_t *s, @@ -151,12 +153,12 @@ static int set_range(const struct motion_sensor_t *s, */ mutex_lock(s->mutex); - ret = raw_read8(s->addr, ctrl_reg, &ctrl_val); + ret = raw_read8(s->port, s->addr, ctrl_reg, &ctrl_val); if (ret != EC_SUCCESS) goto gyro_cleanup; ctrl_val = (ctrl_val & ~L3GD20_RANGE_MASK) | reg_val; - ret = raw_write8(s->addr, ctrl_reg, ctrl_val); + ret = raw_write8(s->port, s->addr, ctrl_reg, ctrl_val); /* Now that we have set the range, update the driver's value. */ if (ret == EC_SUCCESS) @@ -207,20 +209,20 @@ static int set_data_rate(const struct motion_sensor_t *s, */ mutex_lock(s->mutex); - ret = raw_read8(s->addr, ctrl_reg, &val); + ret = raw_read8(s->port, s->addr, ctrl_reg, &val); if (ret != EC_SUCCESS) goto gyro_cleanup; val = (val & ~(L3GD20_ODR_MASK | L3GD20_ODR_PD_MASK)) | (reg_val & ~L3GD20_LOW_ODR_MASK); - ret = raw_write8(s->addr, ctrl_reg, val); + ret = raw_write8(s->port, s->addr, ctrl_reg, val); /* Now that we have set the odr, update the driver's value. */ if (ret == EC_SUCCESS) data->base.odr = get_engineering_val(reg_val, data_rates, odr_tbl_size); - ret = raw_read8(s->addr, L3GD20_LOW_ODR, &val); + ret = raw_read8(s->port, s->addr, L3GD20_LOW_ODR, &val); if (ret != EC_SUCCESS) goto gyro_cleanup; @@ -230,7 +232,7 @@ static int set_data_rate(const struct motion_sensor_t *s, else val &= ~1; - ret = raw_write8(s->addr, L3GD20_LOW_ODR, val); + ret = raw_write8(s->port, s->addr, L3GD20_LOW_ODR, val); if (ret != EC_SUCCESS) goto gyro_cleanup; @@ -242,17 +244,17 @@ static int set_data_rate(const struct motion_sensor_t *s, * [3:2] int1_sel = 0; * [1:0] out_sel = 1; */ - ret = raw_read8(s->addr, L3GD20_CTRL_REG5, &val); + ret = raw_read8(s->port, s->addr, L3GD20_CTRL_REG5, &val); if (ret != EC_SUCCESS) goto gyro_cleanup; val |= (1 << 4); /* high-pass filter enabled */ val |= (1 << 0); /* data in data reg are high-pass filtered */ - ret = raw_write8(s->addr, L3GD20_CTRL_REG5, val); + ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG5, val); if (ret != EC_SUCCESS) goto gyro_cleanup; - ret = raw_read8(s->addr, L3GD20_CTRL_REG2, &val); + ret = raw_read8(s->port, s->addr, L3GD20_CTRL_REG2, &val); if (ret != EC_SUCCESS) goto gyro_cleanup; @@ -262,7 +264,7 @@ static int set_data_rate(const struct motion_sensor_t *s, */ val &= 0xf0; val |= 0x04; - ret = raw_write8(s->addr, L3GD20_CTRL_REG2, val); + ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG2, val); gyro_cleanup: mutex_unlock(s->mutex); @@ -313,7 +315,7 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready) { int ret, tmp; - ret = raw_read8(s->addr, L3GD20_STATUS_REG, &tmp); + ret = raw_read8(s->port, s->addr, L3GD20_STATUS_REG, &tmp); if (ret != EC_SUCCESS) { CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type); @@ -350,10 +352,10 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) xyz_reg = get_xyz_reg(s->type); /* Read 6 bytes starting at xyz_reg */ - i2c_lock(I2C_PORT_GYRO, 1); - ret = i2c_xfer(I2C_PORT_GYRO, s->addr, + i2c_lock(s->port, 1); + ret = i2c_xfer(s->port, s->addr, &xyz_reg, 1, raw, 6, I2C_XFER_SINGLE); - i2c_lock(I2C_PORT_GYRO, 0); + i2c_lock(s->port, 0); if (ret != EC_SUCCESS) { CPRINTF("[%T %s type:0x%X RD XYZ Error]", @@ -379,7 +381,7 @@ static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; - ret = raw_read8(s->addr, L3GD20_WHO_AM_I_REG, &tmp); + ret = raw_read8(s->port, s->addr, L3GD20_WHO_AM_I_REG, &tmp); if (ret) return EC_ERROR_UNKNOWN; @@ -387,19 +389,19 @@ static int init(const struct motion_sensor_t *s) return EC_ERROR_ACCESS_DENIED; /* All axes are enabled */ - ret = raw_write8(s->addr, L3GD20_CTRL_REG1, 0x0f); + ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG1, 0x0f); if (ret) return EC_ERROR_UNKNOWN; mutex_lock(s->mutex); - ret = raw_read8(s->addr, L3GD20_CTRL_REG4, &tmp); + ret = raw_read8(s->port, s->addr, L3GD20_CTRL_REG4, &tmp); if (ret) { mutex_unlock(s->mutex); return EC_ERROR_UNKNOWN; } tmp |= L3GD20_BDU_ENABLE; - ret = raw_write8(s->addr, L3GD20_CTRL_REG4, tmp); + ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG4, tmp); mutex_unlock(s->mutex); if (ret) return EC_ERROR_UNKNOWN; diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c index 6f81ea407a..2eb736a722 100644 --- a/driver/mag_bmm150.c +++ b/driver/mag_bmm150.c @@ -67,9 +67,9 @@ #define BMI150_READ_16BIT_COM_REG(store_, addr_) do { \ int val; \ - raw_mag_read8(s->addr, (addr_), &val); \ + raw_mag_read8(s->port, s->addr, (addr_), &val); \ store_ = val; \ - raw_mag_read8(s->addr, (addr_) + 1, &val); \ + raw_mag_read8(s->port, s->addr, (addr_) + 1, &val); \ store_ |= (val << 8); \ } while (0) @@ -82,10 +82,10 @@ int bmm150_init(const struct motion_sensor_t *s) struct mag_cal_t *moc = BMM150_CAL(s); /* Set the compass from Suspend to Sleep */ - ret = raw_mag_write8(s->addr, BMM150_PWR_CTRL, BMM150_PWR_ON); + ret = raw_mag_write8(s->port, s->addr, BMM150_PWR_CTRL, BMM150_PWR_ON); msleep(4); /* Now we can read the device id */ - ret = raw_mag_read8(s->addr, BMM150_CHIP_ID, &val); + ret = raw_mag_read8(s->port, s->addr, BMM150_CHIP_ID, &val); if (ret) return EC_ERROR_UNKNOWN; @@ -93,21 +93,21 @@ int bmm150_init(const struct motion_sensor_t *s) return EC_ERROR_ACCESS_DENIED; /* Read the private registers for compensation */ - ret = raw_mag_read8(s->addr, BMM150_REGA_DIG_X1, &val); + ret = raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_X1, &val); if (ret) return EC_ERROR_UNKNOWN; regs->dig1[X] = val; - raw_mag_read8(s->addr, BMM150_REGA_DIG_Y1, &val); + raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y1, &val); regs->dig1[Y] = val; - raw_mag_read8(s->addr, BMM150_REGA_DIG_X2, &val); + raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_X2, &val); regs->dig2[X] = val; - raw_mag_read8(s->addr, BMM150_REGA_DIG_Y2, &val); + raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y2, &val); regs->dig2[Y] = val; - raw_mag_read8(s->addr, BMM150_REGA_DIG_XY1, &val); + raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY1, &val); regs->dig_xy1 = val; - raw_mag_read8(s->addr, BMM150_REGA_DIG_XY2, &val); + raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY2, &val); regs->dig_xy2 = val; BMI150_READ_16BIT_COM_REG(regs->dig_z1, BMM150_REGA_DIG_Z1_LSB); @@ -118,16 +118,16 @@ int bmm150_init(const struct motion_sensor_t *s) /* Set the repetition in "Regular Preset" */ - raw_mag_write8(s->addr, BMM150_REPXY, BMM150_REP(SPECIAL, XY)); - raw_mag_write8(s->addr, BMM150_REPZ, BMM150_REP(SPECIAL, Z)); - ret = raw_mag_read8(s->addr, BMM150_REPXY, &val); + raw_mag_write8(s->port, s->addr, BMM150_REPXY, BMM150_REP(SPECIAL, XY)); + raw_mag_write8(s->port, s->addr, BMM150_REPZ, BMM150_REP(SPECIAL, Z)); + ret = raw_mag_read8(s->port, s->addr, BMM150_REPXY, &val); CPRINTS("repxy: 0x%02x", val); - ret = raw_mag_read8(s->addr, BMM150_REPZ, &val); + ret = raw_mag_read8(s->port, s->addr, BMM150_REPZ, &val); CPRINTS("repz: 0x%02x", val); /* * Set the compass forced mode, to sleep after each measure. */ - ret = raw_mag_write8(s->addr, BMM150_OP_CTRL, + ret = raw_mag_write8(s->port, s->addr, BMM150_OP_CTRL, BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET); init_mag_cal(moc); diff --git a/include/motion_sense.h b/include/motion_sense.h index cd830307e3..2aea41a698 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -72,8 +72,12 @@ struct motion_sensor_t { const struct accelgyro_drv *drv; struct mutex *mutex; void *drv_data; + + /* i2c port */ + uint8_t port; /* i2c address or SPI slave logic GPIO. */ uint8_t addr; + const matrix_3x3_t *rot_standard_ref; /* diff --git a/test/motion_lid.c b/test/motion_lid.c index 224b12a26b..81ab132300 100644 --- a/test/motion_lid.c +++ b/test/motion_lid.c @@ -117,6 +117,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &test_motion_sense, .mutex = NULL, .drv_data = NULL, + .port = 0, .addr = 0, .rot_standard_ref = &base_standard_ref, .default_range = 2, /* g, enough for laptop. */ @@ -150,6 +151,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &test_motion_sense, .mutex = NULL, .drv_data = NULL, + .port = 0, .addr = 0, .rot_standard_ref = &lid_standard_ref, .default_range = 2, /* g, enough for laptop. */ |