summaryrefslogtreecommitdiff
path: root/common/cbi.c
diff options
context:
space:
mode:
authorJonathan Brandmeyer <jbrandmeyer@chromium.org>2018-08-07 16:04:23 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-08-09 22:04:40 -0700
commit740427a24398b3fd66904e913b742f751371d09c (patch)
tree1efe5fd4db314fbbb44bdd3a5bc726c4ee818ad0 /common/cbi.c
parentaba9f5e09f7fb1f18a297fb5552404706a642351 (diff)
downloadchrome-ec-740427a24398b3fd66904e913b742f751371d09c.tar.gz
drivers: Refactor to use high-level i2c APIs
Using the high-level APIs for block transfers eliminates some code duplication and error-prone manual locking sequences. - common/cbi: Block transfers - driver/accel_bma2x2: Block transfers - driver/accel_kionix: Block transfers - driver/accelgyro_bmi160: Block transfers - driver/accelgyro_lsm6ds0: Block transfers - driver/baro_bmp280: Block and byte transfers - driver/charger/rt946x: Block transfers - driver/gyro_l3gd20h: Block transfers - driver/stm_mems_common: Block transfers - driver/tcpm: Block transfers TEST=buildall; motionsense and PD testing on Grunt convertible which exercises the bma160, kionix and tcpcm drivers. BRANCH=none BUG=chromium:871851 Change-Id: I1732253a244c3343459265ce1e1e54488cee65b8 Signed-off-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1167958 Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common/cbi.c')
-rw-r--r--common/cbi.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/common/cbi.c b/common/cbi.c
index 231ee18e13..3a686085c5 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -72,14 +72,8 @@ static struct cbi_header * const head = (struct cbi_header *)cbi;
static int read_eeprom(uint8_t offset, uint8_t *in, int in_size)
{
- int ret;
-
- i2c_lock(I2C_PORT_EEPROM, 1);
- ret = i2c_xfer(I2C_PORT_EEPROM, I2C_ADDR_EEPROM,
- &offset, 1, in, in_size, I2C_XFER_SINGLE);
- i2c_lock(I2C_PORT_EEPROM, 0);
-
- return ret;
+ return i2c_read_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM, offset,
+ in, in_size);
}
/*
@@ -199,8 +193,7 @@ static int write_board_info(void)
/* The code is only tested for ST M24C02, whose page size for a single
* write is 16 byte. To support different EEPROMs, you may need to
* craft the i2c packets accordingly. */
- uint8_t buf[EEPROM_PAGE_WRITE_SIZE + 1]; /* '1' for offset byte */
- uint8_t *p = cbi;
+ const uint8_t *p = cbi;
int rest = head->total_size;
if (eeprom_is_write_protected()) {
@@ -208,24 +201,19 @@ static int write_board_info(void)
return EC_ERROR_ACCESS_DENIED;
}
- buf[0] = 0; /* Offset 0 */
while (rest > 0) {
int size = MIN(EEPROM_PAGE_WRITE_SIZE, rest);
int rv;
- rest -= size;
- memcpy(&buf[1], p, size);
- i2c_lock(I2C_PORT_EEPROM, 1);
- rv = i2c_xfer(I2C_PORT_EEPROM, I2C_ADDR_EEPROM, buf, size + 1,
- NULL, 0, I2C_XFER_SINGLE);
- i2c_lock(I2C_PORT_EEPROM, 0);
+ rv = i2c_write_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM,
+ p - cbi, p, size);
if (rv) {
CPRINTS("Failed to write for %d", rv);
return rv;
}
/* Wait for internal write cycle completion */
msleep(EEPROM_PAGE_WRITE_MS);
- buf[0] += size;
p += size;
+ rest -= size;
}
return EC_SUCCESS;