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/als_opt3001.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/als_opt3001.c')
-rw-r--r-- | driver/als_opt3001.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/driver/als_opt3001.c b/driver/als_opt3001.c index fd5dded45d..42a06bfdcc 100644 --- a/driver/als_opt3001.c +++ b/driver/als_opt3001.c @@ -17,7 +17,8 @@ static int opt3001_i2c_read(const int reg, int *data_ptr) { int ret; - ret = i2c_read16(I2C_PORT_ALS, OPT3001_I2C_ADDR, reg, data_ptr); + ret = i2c_read16__7bf(I2C_PORT_ALS, OPT3001_I2C_ADDR__7bf, + reg, data_ptr); if (!ret) *data_ptr = ((*data_ptr << 8) & 0xFF00) | ((*data_ptr >> 8) & 0x00FF); @@ -31,7 +32,8 @@ static int opt3001_i2c_read(const int reg, int *data_ptr) static int opt3001_i2c_write(const int reg, int data) { data = ((data << 8) & 0xFF00) | ((data >> 8) & 0x00FF); - return i2c_write16(I2C_PORT_ALS, OPT3001_I2C_ADDR, reg, data); + return i2c_write16__7bf(I2C_PORT_ALS, OPT3001_I2C_ADDR__7bf, + reg, data); } /** @@ -108,12 +110,14 @@ struct i2c_stress_test_dev opt3001_i2c_stress_test_dev = { /** * Read register from OPT3001 light sensor. */ -static int opt3001_i2c_read(const int port, const int addr, const int reg, - int *data_ptr) +static int opt3001_i2c_read__7bf(const int port, + const uint16_t i2c_addr__7bf, + const int reg, int *data_ptr) { int ret; - ret = i2c_read16(port, addr, reg, data_ptr); + ret = i2c_read16__7bf(port, i2c_addr__7bf, + reg, data_ptr); if (!ret) *data_ptr = ((*data_ptr << 8) & 0xFF00) | ((*data_ptr >> 8) & 0x00FF); @@ -124,11 +128,13 @@ static int opt3001_i2c_read(const int port, const int addr, const int reg, /** * Write register to OPT3001 light sensor. */ -static int opt3001_i2c_write(const int port, const int addr, const int reg, - int data) +static int opt3001_i2c_write__7bf(const int port, + const uint16_t i2c_addr__7bf, + const int reg, int data) { data = ((data << 8) & 0xFF00) | ((data >> 8) & 0x00FF); - return i2c_write16(port, addr, reg, data); + return i2c_write16__7bf(port, i2c_addr__7bf, + reg, data); } /** @@ -140,7 +146,8 @@ int opt3001_read_lux(const struct motion_sensor_t *s, intv3_t v) int ret; int data; - ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_RESULT, &data); + ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_RESULT, &data); if (ret) return ret; @@ -211,13 +218,15 @@ static int opt3001_set_data_rate(const struct motion_sensor_t *s, if (rate > 1000) rate = 1000; } - rv = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_CONFIGURE, ®); + rv = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_CONFIGURE, ®); if (rv) return rv; - rv = opt3001_i2c_write(s->port, s->addr, OPT3001_REG_CONFIGURE, + rv = opt3001_i2c_write__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_CONFIGURE, (reg & OPT3001_MODE_MASK) | - (mode << OPT3001_MODE_OFFSET)); + (mode << OPT3001_MODE_OFFSET)); if (rv) return rv; @@ -262,13 +271,15 @@ static int opt3001_init(const struct motion_sensor_t *s) int data; int ret; - ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_MAN_ID, &data); + ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_MAN_ID, &data); if (ret) return ret; if (data != OPT3001_MANUFACTURER_ID) return EC_ERROR_ACCESS_DENIED; - ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_DEV_ID, &data); + ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_DEV_ID, &data); if (ret) return ret; if (data != OPT3001_DEVICE_ID) @@ -279,7 +290,8 @@ static int opt3001_init(const struct motion_sensor_t *s) * [11] : 1b Conversion time 800ms * [4] : 1b Latched window-style comparison operation */ - opt3001_i2c_write(s->port, s->addr, OPT3001_REG_CONFIGURE, 0xC810); + opt3001_i2c_write__7bf(s->port, s->i2c_spi_addr__7bf, + OPT3001_REG_CONFIGURE, 0xC810); opt3001_set_range(s, s->default_range, 0); @@ -304,8 +316,8 @@ struct i2c_stress_test_dev opt3001_i2c_stress_test_dev = { .read_val = OPT3001_DEVICE_ID, .write_reg = OPT3001_REG_INT_LIMIT_LSB, }, - .i2c_read = &opt3001_i2c_read, - .i2c_write = &opt3001_i2c_write, + .i2c_read__7bf = &opt3001_i2c_read__7bf, + .i2c_write__7bf = &opt3001_i2c_write__7bf, }; #endif /* CONFIG_CMD_I2C_STRESS_TEST_ALS */ #endif /* HAS_TASK_ALS */ |