diff options
author | Denis Brockus <dbrockus@chromium.org> | 2019-06-25 12:44:16 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-19 21:11:02 +0000 |
commit | d1a18f82ed831d4e640336ff5571f5fa64bc7b36 (patch) | |
tree | c46aeb6136de1c27c66e3d5f662e9620161bef7b /driver/mag_bmm150.c | |
parent | 1f14229fa7e499dfcee07d17add187598ff0a46c (diff) | |
download | chrome-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/mag_bmm150.c')
-rw-r--r-- | driver/mag_bmm150.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c index 9598d85105..30555cbe56 100644 --- a/driver/mag_bmm150.c +++ b/driver/mag_bmm150.c @@ -19,8 +19,8 @@ #ifdef CONFIG_MAG_BMI160_BMM150 #include "driver/accelgyro_bmi160.h" -#define raw_mag_read8 bmi160_sec_raw_read8 -#define raw_mag_write8 bmi160_sec_raw_write8 +#define raw_mag_read8__7bf bmi160_sec_raw_read8__7bf +#define raw_mag_write8__7bf bmi160_sec_raw_write8__7bf #else #error "Not implemented" #endif @@ -73,9 +73,9 @@ #define BMI150_READ_16BIT_COM_REG(store_, addr_) do { \ int val; \ - raw_mag_read8(s->port, s->addr, (addr_), &val); \ + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, (addr_), &val); \ store_ = val; \ - raw_mag_read8(s->port, s->addr, (addr_) + 1, &val); \ + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, (addr_) + 1, &val); \ store_ |= (val << 8); \ } while (0) @@ -88,10 +88,12 @@ 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->port, s->addr, BMM150_PWR_CTRL, BMM150_PWR_ON); + ret = raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_PWR_CTRL, BMM150_PWR_ON); msleep(4); /* Now we can read the device id */ - ret = raw_mag_read8(s->port, s->addr, BMM150_CHIP_ID, &val); + ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_CHIP_ID, &val); if (ret) return EC_ERROR_UNKNOWN; @@ -99,21 +101,27 @@ 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->port, s->addr, BMM150_REGA_DIG_X1, &val); + ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_X1, &val); if (ret) return EC_ERROR_UNKNOWN; regs->dig1[X] = val; - raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y1, &val); + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_Y1, &val); regs->dig1[Y] = val; - raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_X2, &val); + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_X2, &val); regs->dig2[X] = val; - raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y2, &val); + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_Y2, &val); regs->dig2[Y] = val; - raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY1, &val); + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_XY1, &val); regs->dig_xy1 = val; - raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY2, &val); + raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REGA_DIG_XY2, &val); regs->dig_xy2 = val; BMI150_READ_16BIT_COM_REG(regs->dig_z1, BMM150_REGA_DIG_Z1_LSB); @@ -124,15 +132,20 @@ int bmm150_init(const struct motion_sensor_t *s) /* Set the repetition in "Regular Preset" */ - 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); - ret = raw_mag_read8(s->port, s->addr, BMM150_REPZ, &val); + raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REPXY, BMM150_REP(SPECIAL, XY)); + raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REPZ, BMM150_REP(SPECIAL, Z)); + ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REPXY, &val); + ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_REPZ, &val); /* * Set the compass forced mode, to sleep after each measure. */ - ret = raw_mag_write8(s->port, s->addr, BMM150_OP_CTRL, - BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET); + ret = raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf, + BMM150_OP_CTRL, + BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET); init_mag_cal(moc); moc->radius = 0.0f; |