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 /chip/stm32/usb_power.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 'chip/stm32/usb_power.c')
-rw-r--r-- | chip/stm32/usb_power.c | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/chip/stm32/usb_power.c b/chip/stm32/usb_power.c index 7e4206e83b..4cf8bac99e 100644 --- a/chip/stm32/usb_power.c +++ b/chip/stm32/usb_power.c @@ -249,7 +249,7 @@ static int usb_power_state_addina(struct usb_power_config const *config, ina = state->ina_cfg + state->ina_count; ina->port = cmd->addina.port; - ina->addr = (cmd->addina.addr) << 1; /* 7 to 8 bit addr. */ + ina->addr__7bf = cmd->addina.addr__7bf; ina->rs = cmd->addina.rs; ina->type = cmd->addina.type; @@ -270,7 +270,7 @@ static int usb_power_state_addina(struct usb_power_config const *config, struct usb_power_ina_cfg *tmp = state->ina_cfg + i; if ((tmp->port == ina->port) && - (tmp->addr == ina->addr)) { + (tmp->addr__7bf == ina->addr__7bf)) { ina->shared = 1; tmp->shared = 1; } @@ -406,42 +406,46 @@ int reg_type_mapping(enum usb_power_ina_type ina_type) } } -uint16_t ina2xx_readagain(uint8_t port, uint8_t addr) +uint16_t ina2xx_readagain__7bf(uint8_t port, uint16_t slave_addr__7bf) { int res; uint16_t val; - res = i2c_xfer(port, addr, NULL, 0, (uint8_t *)&val, sizeof(uint16_t)); + res = i2c_xfer__7bf(port, slave_addr__7bf, + NULL, 0, (uint8_t *)&val, sizeof(uint16_t)); if (res) { CPRINTS("INA2XX I2C readagain failed p:%d a:%02x", - (int)port, (int)addr); + (int)port, (int)I2C_GET_ADDR__7b(slave_addr__7bf)); return 0x0bad; } return (val >> 8) | ((val & 0xff) << 8); } -uint16_t ina2xx_read(uint8_t port, uint8_t addr, uint8_t reg) +uint16_t ina2xx_read__7bf(uint8_t port, uint16_t slave_addr__7bf, + uint8_t reg) { int res; int val; - res = i2c_read16(port, addr, reg, &val); + res = i2c_read16__7bf(port, slave_addr__7bf, reg, &val); if (res) { CPRINTS("INA2XX I2C read failed p:%d a:%02x, r:%02x", - (int)port, (int)addr, (int)reg); + (int)port, (int)I2C_GET_ADDR__7b(slave_addr__7bf), + (int)reg); return 0x0bad; } return (val >> 8) | ((val & 0xff) << 8); } -int ina2xx_write(uint8_t port, uint8_t addr, uint8_t reg, uint16_t val) +int ina2xx_write__7bf(uint8_t port, uint16_t slave_addr__7bf, + uint8_t reg, uint16_t val) { int res; uint16_t be_val = (val >> 8) | ((val & 0xff) << 8); - res = i2c_write16(port, addr, reg, be_val); + res = i2c_write16__7bf(port, slave_addr__7bf, reg, be_val); if (res) CPRINTS("INA2XX I2C write failed"); return res; @@ -505,10 +509,13 @@ static int usb_power_init_inas(struct usb_power_config const *config) { int conf, cal; - conf = ina2xx_read(ina->port, ina->addr, INA231_REG_CONF); - cal = ina2xx_read(ina->port, ina->addr, INA231_REG_CAL); + conf = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_CONF); + cal = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_CAL); CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, cal:%x", - i, ina->port, ina->addr, conf, cal); + i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf), + conf, cal); } #endif /* @@ -529,7 +536,8 @@ static int usb_power_init_inas(struct usb_power_config const *config) if (ina->scale == 0) return -1; value = (5120000 * 100) / (ina->scale * ina->rs); - ret = ina2xx_write(ina->port, ina->addr, INA231_REG_CAL, value); + ret = ina2xx_write__7bf(ina->port, ina->addr__7bf, + INA231_REG_CAL, value); if (ret != EC_SUCCESS) { CPRINTS("[CAP] usb_power_init_inas CAL FAIL: %d", ret); return ret; @@ -538,7 +546,8 @@ static int usb_power_init_inas(struct usb_power_config const *config) { int actual; - actual = ina2xx_read(ina->port, ina->addr, INA231_REG_CAL); + actual = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_CAL); CPRINTS("[CAP] scale: %d uA/div, %d uW/div, cal:%x act:%x", ina->scale / 100, ina->scale*25/100, value, actual); } @@ -548,8 +557,8 @@ static int usb_power_init_inas(struct usb_power_config const *config) INA231_CONF_SHUNT_TIME(shunt_time) | INA231_CONF_BUS_TIME(shunt_time) | INA231_CONF_AVG(avg); - ret = ina2xx_write( - ina->port, ina->addr, INA231_REG_CONF, value); + ret = ina2xx_write__7bf(ina->port, ina->addr__7bf, + INA231_REG_CONF, value); if (ret != EC_SUCCESS) { CPRINTS("[CAP] usb_power_init_inas CONF FAIL: %d", ret); return ret; @@ -558,26 +567,31 @@ static int usb_power_init_inas(struct usb_power_config const *config) { int actual; - actual = ina2xx_read(ina->port, ina->addr, INA231_REG_CONF); + actual = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_CONF); CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, act:%x", - i, ina->port, ina->addr, value, actual); + i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf), + value, actual); } #endif #ifdef USB_POWER_VERBOSE { int busv_mv = - (ina2xx_read(ina->port, ina->addr, INA231_REG_BUSV) + (ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_BUSV) * 125) / 100; CPRINTS("[CAP] %d (%d,0x%02x): busv:%dmv", - i, ina->port, ina->addr, busv_mv); + i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf), + busv_mv); } #endif /* Initialize read from power register. This register address * will be cached and all ina2xx_readagain() calls will read * from the same address. */ - ina2xx_read(ina->port, ina->addr, reg_type_mapping(ina->type)); + ina2xx_read__7bf(ina->port, ina->addr__7bf, + reg_type_mapping(ina->type)); #ifdef USB_POWER_VERBOSE CPRINTS("[CAP] %d (%d,0x%02x): type:%d", (int)(ina->type)); #endif @@ -635,10 +649,11 @@ static int usb_power_get_samples(struct usb_power_config const *config) * transaction. */ if (ina->shared) - regval = ina2xx_read(ina->port, ina->addr, + regval = ina2xx_read__7bf(ina->port, ina->addr__7bf, reg_type_mapping(ina->type)); else - regval = ina2xx_readagain(ina->port, ina->addr); + regval = ina2xx_readagain__7bf(ina->port, + ina->addr__7bf); r->power[i] = regval; #ifdef USB_POWER_VERBOSE { @@ -647,10 +662,14 @@ static int usb_power_get_samples(struct usb_power_config const *config) int voltage; int bvoltage; - voltage = ina2xx_read(ina->port, ina->addr, INA231_REG_RSHV); - bvoltage = ina2xx_read(ina->port, ina->addr, INA231_REG_BUSV); - current = ina2xx_read(ina->port, ina->addr, INA231_REG_CURR); - power = ina2xx_read(ina->port, ina->addr, INA231_REG_PWR); + voltage = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_RSHV); + bvoltage = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_BUSV); + current = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_CURR); + power = ina2xx_read__7bf(ina->port, ina->addr__7bf, + INA231_REG_PWR); { int uV = ((int)voltage * 25) / 10; int mV = ((int)bvoltage * 125) / 100; @@ -659,7 +678,8 @@ static int usb_power_get_samples(struct usb_power_config const *config) int uW = (((int)power * ina->scale*25)/100); CPRINTS("[CAP] %d (%d,0x%02x): %dmV / %dmO = %dmA", - i, ina->port, ina->addr, uV/1000, ina->rs, uA/1000); + i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf), + uV/1000, ina->rs, uA/1000); CPRINTS("[CAP] %duV %dmV %duA %dCuA " "%duW v:%04x, b:%04x, p:%04x", uV, mV, uA, CuA, uW, voltage, bvoltage, power); |