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_si114x.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_si114x.c')
-rw-r--r-- | driver/als_si114x.c | 92 |
1 files changed, 52 insertions, 40 deletions
diff --git a/driver/als_si114x.c b/driver/als_si114x.c index b51cf8cfc6..f0b3165e67 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -27,28 +27,28 @@ static int init(const struct motion_sensor_t *s); /** * Read 8bit register from device. */ -static inline int raw_read8(const int port, const int addr, const int reg, - int *data_ptr) +static inline int raw_read8__7bf(const int port, const uint16_t i2c_addr__7bf, + const int reg, int *data_ptr) { - return i2c_read8(port, addr, reg, data_ptr); + return i2c_read8__7bf(port, i2c_addr__7bf, reg, data_ptr); } /** * Write 8bit register from device. */ -static inline int raw_write8(const int port, const int addr, const int reg, - int data) +static inline int raw_write8__7bf(const int port, const uint16_t i2c_addr__7bf, + const int reg, int data) { - return i2c_write8(port, addr, reg, data); + return i2c_write8__7bf(port, i2c_addr__7bf, reg, data); } /** * Read 16bit register from device. */ -static inline int raw_read16(const int port, const int addr, const int reg, - int *data_ptr) +static inline int raw_read16__7bf(const int port, const uint16_t i2c_addr__7bf, + const int reg, int *data_ptr) { - return i2c_read16(port, addr, reg, data_ptr); + return i2c_read16__7bf(port, i2c_addr__7bf, reg, data_ptr); } /* helper function to operate on parameter values: op can be query/set/or/and */ @@ -62,17 +62,19 @@ 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->port, s->addr, SI114X_REG_PARAM_WR, *value); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PARAM_WR, *value); if (ret != EC_SUCCESS) goto error; } - ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, - op | (param & 0x1F)); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_COMMAND, op | (param & 0x1F)); if (ret != EC_SUCCESS) goto error; - ret = raw_read8(s->port, s->addr, SI114X_REG_PARAM_RD, value); + ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PARAM_RD, value); if (ret != EC_SUCCESS) goto error; @@ -96,7 +98,7 @@ 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->port, s->addr, + ret = raw_read16__7bf(s->port, s->i2c_spi_addr__7bf, type_data->base_data_reg + i * 2, &val); if (ret) @@ -196,7 +198,8 @@ 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->port, s->addr, SI114X_REG_IRQ_STATUS, &val); + ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_IRQ_STATUS, &val); if (ret) return ret; @@ -204,7 +207,8 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) return EC_ERROR_INVAL; /* clearing IRQ */ - ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_STATUS, + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_IRQ_STATUS, val & type_data->irq_flags); if (ret != EC_SUCCESS) CPRINTS("clearing irq failed"); @@ -216,8 +220,9 @@ 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->port, s->addr, SI114X_REG_COMMAND, - SI114X_CMD_PS_FORCE); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_COMMAND, + SI114X_CMD_PS_FORCE); data->state = SI114X_PS_IN_PROGRESS; } else { data->state = SI114X_IDLE; @@ -228,8 +233,9 @@ 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->port, s->addr, SI114X_REG_COMMAND, - SI114X_CMD_ALS_FORCE); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_COMMAND, + SI114X_CMD_ALS_FORCE); data->state = SI114X_ALS_IN_PROGRESS; } else { data->state = SI114X_IDLE; @@ -282,7 +288,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v) CPRINTS("Invalid sensor type"); return EC_ERROR_INVAL; } - ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, cmd); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_COMMAND, cmd); #ifdef CONFIG_ALS_SI114X_POLLING hook_call_deferred(&si114x_read_deferred_data, SI114x_POLLING_DELAY); @@ -370,63 +377,68 @@ static int si114x_initialize(const struct motion_sensor_t *s) int ret, val; /* send reset command */ - ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, - SI114X_CMD_RESET); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_COMMAND, SI114X_CMD_RESET); if (ret != EC_SUCCESS) return ret; msleep(20); /* hardware key, magic value */ - ret = raw_write8(s->port, s->addr, SI114X_REG_HW_KEY, 0x17); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_HW_KEY, 0x17); if (ret != EC_SUCCESS) return ret; msleep(20); /* interrupt configuration, interrupt output enable */ - ret = raw_write8(s->port, s->addr, SI114X_REG_INT_CFG, - SI114X_INT_CFG_OE); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_INT_CFG, SI114X_INT_CFG_OE); if (ret != EC_SUCCESS) return ret; /* enable interrupt for certain activities */ - ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_ENABLE, - SI114X_PS3_IE | SI114X_PS2_IE | SI114X_PS1_IE | - SI114X_ALS_INT0_IE); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + 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->port, s->addr, SI114X_REG_MEAS_RATE, 0); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_MEAS_RATE, 0); if (ret != EC_SUCCESS) return ret; /* measure ALS every time device wakes up */ - ret = raw_write8(s->port, s->addr, SI114X_REG_ALS_RATE, 0); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_ALS_RATE, 0); if (ret != EC_SUCCESS) return ret; /* measure proximity every time device wakes up */ - ret = raw_write8(s->port, s->addr, SI114X_REG_PS_RATE, 0); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + 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->port, s->addr, - SI114X_REG_PS_LED3, 0x0f); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PS_LED3, 0x0f); if (ret != EC_SUCCESS) return ret; - ret = raw_write8(s->port, s->addr, - SI114X_REG_PS_LED21, 0xff); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PS_LED21, 0xff); break; case 2: - ret = raw_write8(s->port, s->addr, - SI114X_REG_PS_LED21, 0xff); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PS_LED21, 0xff); break; case 1: - ret = raw_write8(s->port, s->addr, - SI114X_REG_PS_LED21, 0x0f); + ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, + SI114X_REG_PS_LED21, 0x0f); break; } if (ret != EC_SUCCESS) |