summaryrefslogtreecommitdiff
path: root/driver/sensorhub_lsm6dsm.c
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-06-25 12:44:16 -0600
committerCommit Bot <commit-bot@chromium.org>2019-07-19 21:11:02 +0000
commitd1a18f82ed831d4e640336ff5571f5fa64bc7b36 (patch)
treec46aeb6136de1c27c66e3d5f662e9620161bef7b /driver/sensorhub_lsm6dsm.c
parent1f14229fa7e499dfcee07d17add187598ff0a46c (diff)
downloadchrome-ec-d1a18f82ed831d4e640336ff5571f5fa64bc7b36.tar.gz
Use 7bit I2C/SPI slave addresses in EC
Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'driver/sensorhub_lsm6dsm.c')
-rw-r--r--driver/sensorhub_lsm6dsm.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/driver/sensorhub_lsm6dsm.c b/driver/sensorhub_lsm6dsm.c
index f663f5a5ae..711294fb98 100644
--- a/driver/sensorhub_lsm6dsm.c
+++ b/driver/sensorhub_lsm6dsm.c
@@ -21,12 +21,12 @@ static int set_reg_bit_field(const struct motion_sensor_t *s,
int tmp;
int ret;
- ret = st_raw_read8(s->port, s->addr, reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &tmp);
if (ret != EC_SUCCESS)
return ret;
tmp |= bit_field;
- return st_raw_write8(s->port, s->addr, reg, tmp);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, tmp);
}
static int clear_reg_bit_field(const struct motion_sensor_t *s,
@@ -35,12 +35,12 @@ static int clear_reg_bit_field(const struct motion_sensor_t *s,
int tmp;
int ret;
- ret = st_raw_read8(s->port, s->addr, reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &tmp);
if (ret != EC_SUCCESS)
return ret;
tmp &= ~(bit_field);
- return st_raw_write8(s->port, s->addr, reg, tmp);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, tmp);
}
static inline int enable_sensorhub_func(const struct motion_sensor_t *s)
@@ -89,7 +89,8 @@ static inline int disable_aux_i2c_master(const struct motion_sensor_t *s)
static inline int restore_master_cfg(const struct motion_sensor_t *s,
int cache)
{
- return st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR, cache);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR, cache);
}
static int enable_i2c_pass_through(const struct motion_sensor_t *s,
@@ -97,7 +98,8 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
{
int ret;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR, cache);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR, cache);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCR error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -109,8 +111,9 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
* Wait is for any pending bus activity(probably read) to settle down
* so that there is no bus contention.
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR,
- *cache | LSM6DSM_EXT_TRIGGER_EN);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR,
+ *cache | LSM6DSM_EXT_TRIGGER_EN);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCETEN error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -118,8 +121,10 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
}
msleep(10);
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR,
- *cache & ~(LSM6DSM_EXT_TRIGGER_EN | LSM6DSM_I2C_MASTER_ON));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR,
+ *cache & ~(LSM6DSM_EXT_TRIGGER_EN
+ | LSM6DSM_I2C_MASTER_ON));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCC error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -127,7 +132,7 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
return ret;
}
- return st_raw_write8(s->port, s->addr,
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
LSM6DSM_MASTER_CFG_ADDR, LSM6DSM_I2C_PASS_THRU_MODE);
}
@@ -136,37 +141,43 @@ static inline int power_down_accel(const struct motion_sensor_t *s,
{
int ret;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_CTRL1_ADDR, cache);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR, cache);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CTRL1R error ret: %d\n",
__func__, s->name, s->type, ret);
return ret;
}
- return st_raw_write8(s->port, s->addr, LSM6DSM_CTRL1_ADDR,
- *cache & ~LSM6DSM_XL_ODR_MASK);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR,
+ *cache & ~LSM6DSM_XL_ODR_MASK);
}
static inline int restore_ctrl1(const struct motion_sensor_t *s, int cache)
{
- return st_raw_write8(s->port, s->addr,
- LSM6DSM_CTRL1_ADDR, cache);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR, cache);
}
-static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
- uint8_t reg, uint8_t len)
+static int config_slv0_read__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint16_t reg, uint8_t len)
{
int ret;
+ uint16_t addr__8b = I2C_GET_ADDR__7b(slv_addr__7bf) << 1;
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_ADD_ADDR,
- (addr | LSM6DSM_SLV0_RD_BIT));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_ADD_ADDR,
+ (addr__8b | LSM6DSM_SLV0_RD_BIT));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x SA error ret: %d\n",
__func__, s->name, s->type, ret);
return ret;
}
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_SUBADD_ADDR, reg);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_SUBADD_ADDR, reg);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x RA error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -177,8 +188,9 @@ static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
* No decimation for external sensor 0,
* Number of sensors connected to external sensor hub 1
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_CONFIG_ADDR,
- (len & LSM6DSM_SLV0_NUM_OPS_MASK));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_CONFIG_ADDR,
+ (len & LSM6DSM_SLV0_NUM_OPS_MASK));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CFG error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -188,8 +200,9 @@ static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
return EC_SUCCESS;
}
-int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, uint8_t val)
+int sensorhub_config_ext_reg__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t reg, uint8_t val)
{
int ret;
int tmp;
@@ -201,13 +214,13 @@ int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
return ret;
}
- ret = st_raw_write8(s->port, slv_addr, reg, val);
+ ret = st_raw_write8__7bf(s->port, slv_addr__7bf, reg, val);
restore_master_cfg(s, tmp);
return ret;
}
-int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, int len)
+int sensorhub_config_slv0_read__7bf(const struct motion_sensor_t *s,
+ uint16_t slv_addr__7bf, uint8_t reg, int len)
{
int tmp_xl_cfg;
int ret;
@@ -232,7 +245,7 @@ int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
goto out_restore_ctrl1;
}
- ret = config_slv0_read(s, slv_addr, reg, len);
+ ret = config_slv0_read__7bf(s, slv_addr__7bf, reg, len);
disable_ereg_bank_acc(s);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CS0R error ret: %d\n",
@@ -267,8 +280,9 @@ int sensorhub_slv0_data_read(const struct motion_sensor_t *s, uint8_t *raw)
* register as soon as the accel is in power-up mode. So return the
* contents of that register.
*/
- ret = st_raw_read_n_noinc(s->port, s->addr, LSM6DSM_SENSORHUB1_REG,
- raw, OUT_XYZ_SIZE);
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SENSORHUB1_REG,
+ raw, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x SH1R error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -277,9 +291,10 @@ int sensorhub_slv0_data_read(const struct motion_sensor_t *s, uint8_t *raw)
return EC_SUCCESS;
}
-int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
- uint8_t whoami_reg, uint8_t whoami_val,
- uint8_t rst_reg, uint8_t rst_val)
+int sensorhub_check_and_rst__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t whoami_reg, uint8_t whoami_val,
+ uint8_t rst_reg, uint8_t rst_val)
{
int ret, tmp;
int tmp_master_cfg;
@@ -291,7 +306,7 @@ int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
return ret;
}
- ret = st_raw_read8(s->port, slv_addr, whoami_reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, slv_addr__7bf, whoami_reg, &tmp);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x WAIR error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -305,7 +320,7 @@ int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
goto err_restore_master_cfg;
}
- ret = st_raw_write8(s->port, slv_addr, rst_reg, rst_val);
+ ret = st_raw_write8__7bf(s->port, slv_addr__7bf, rst_reg, rst_val);
err_restore_master_cfg:
restore_master_cfg(s, tmp_master_cfg);
return ret;