summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2014-04-07 18:45:14 -0700
committerMarc Jones <marc.jones@se-eng.com>2014-12-16 00:02:43 +0100
commitcdb61a6f5d2268b059ac56da3b69ad0313f3fb90 (patch)
tree57dcfe80e68d872d1080cfc168abc866f0cbffe7 /src/drivers
parentbe6f8cb0f0a2873a9c16dc454cde1f29f4fab765 (diff)
i2c: Replace the i2c API.
The new API is in use in depthcharge and is based around the "i2c_transfer" function instead of i2c_read and i2c_write. The new function takes an array of i2c_seg structures which represent each portion of the transfer after a start bit and before the stop bit. If there's more than one segment, they're seperated by repeated starts. Some wrapper functions have also been added which make certain common operations easy. These include reading or writing a byte from a register or reading or writing a blob of raw data. The i2c device drivers generally use these wrappers but can call the i2c_transfer function directly if the need something different. The tegra i2c driver was very similar to the one in depthcharge and was simple to convert. The Exynos 5250 and 5420 drivers were ported from depthcharge and replace the ones in coreboot. The Exynos 5420 driver was ported from the high speed portion of the one in coreboot and was straightforward to port back. The low speed portion and the Exynos 5250 drivers had been transplanted from U-Boot and were replaced with the depthcharge implementation. BUG=None TEST=Built and booted on nyan with and without EFS. Built and booted on, pit and daisy. BRANCH=None Original-Change-Id: I1e98c3fa2560be25444ab3d0394bb214b9d56e93 Original-Signed-off-by: Gabe Black <gabeblack@google.com> Original-Reviewed-on: https://chromium-review.googlesource.com/193561 Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Original-Reviewed-by: Jimmy Zhang <jimmzhang@nvidia.com> Original-Tested-by: Jimmy Zhang <jimmzhang@nvidia.com> Original-Reviewed-by: Hung-Te Lin <hungte@chromium.org> Original-Commit-Queue: Gabe Black <gabeblack@chromium.org> Original-Tested-by: Gabe Black <gabeblack@chromium.org> (cherry picked from commit 00c423fb2c06c69d580ee3ec0a3892ebf164a5fe) This cherry-pick required additional changes to the following: src/cpu/allwinner/a10/twi.c src/drivers/xpowers/axp209/axp209.c Signed-off-by: Marc Jones <marc.jones@se-eng.com> Change-Id: I691959c66308eeeec219b1bec463b8b365a246d7 Reviewed-on: http://review.coreboot.org/7751 Tested-by: build bot (Jenkins) Reviewed-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/i2c/tpm/tis.c5
-rw-r--r--src/drivers/i2c/tpm/tpm.c19
-rw-r--r--src/drivers/maxim/max77686/max77686.c4
-rw-r--r--src/drivers/parade/ps8625/ps8625.c3
-rw-r--r--src/drivers/ti/tps65090/tps65090.c4
-rw-r--r--src/drivers/xpowers/axp209/axp209.c4
6 files changed, 19 insertions, 20 deletions
diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c
index e8d69acfbf..49bcdd7049 100644
--- a/src/drivers/i2c/tpm/tis.c
+++ b/src/drivers/i2c/tpm/tis.c
@@ -79,10 +79,7 @@ int tis_init(void)
* Probe TPM twice; the first probing might fail because TPM is asleep,
* and the probing can wake up TPM.
*/
- uint8_t tmp = 0;
-
- if (i2c_write(bus, chip, 0, 1, &tmp, sizeof(tmp)) &&
- i2c_write(bus, chip, 0, 1, &tmp, sizeof(tmp)))
+ if (i2c_writeb(bus, chip, 0, 0) && i2c_writeb(bus, chip, 0, 0))
return -1;
return 0;
diff --git a/src/drivers/i2c/tpm/tpm.c b/src/drivers/i2c/tpm/tpm.c
index 837bd234ac..6f6878969c 100644
--- a/src/drivers/i2c/tpm/tpm.c
+++ b/src/drivers/i2c/tpm/tpm.c
@@ -120,8 +120,7 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
if ((tpm_dev.chip_type == SLB9635) || (tpm_dev.chip_type == UNKNOWN)) {
/* slb9635 protocol should work in both cases */
for (count = 0; count < MAX_COUNT; count++) {
- rc = i2c_write(tpm_dev.bus, tpm_dev.addr,
- 0, 0, &addr, 1);
+ rc = i2c_write_raw(tpm_dev.bus, tpm_dev.addr, &addr, 1);
if (rc == 0)
break; /* success, break to skip sleep */
@@ -137,8 +136,8 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
*/
for (count = 0; count < MAX_COUNT; count++) {
udelay(SLEEP_DURATION);
- rc = i2c_read(tpm_dev.bus, tpm_dev.addr,
- 0, 0, buffer, len);
+ rc = i2c_read_raw(tpm_dev.bus, tpm_dev.addr,
+ buffer, len);
if (rc == 0)
break; /* success, break to skip sleep */
@@ -150,9 +149,13 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
* retries should usually not be needed, but are kept just to
* be safe on the safe side.
*/
+ struct i2c_seg aseg = { .read = 0, .chip = tpm_dev.addr,
+ .buf = &addr, .len = 1 };
+ struct i2c_seg dseg = { .read = 1, .chip = tpm_dev.addr,
+ .buf = buffer, .len = len };
for (count = 0; count < MAX_COUNT; count++) {
- rc = i2c_read(tpm_dev.bus, tpm_dev.addr,
- addr, 1, buffer, len);
+ rc = i2c_transfer(tpm_dev.bus, &aseg, 1) ||
+ i2c_transfer(tpm_dev.bus, &dseg, 1);
if (rc == 0)
break; /* break here to skip sleep */
udelay(SLEEP_DURATION);
@@ -186,8 +189,8 @@ static int iic_tpm_write_generic(uint8_t addr, uint8_t *buffer, size_t len,
if (!tpm_dev.bus)
return -1;
for (count = 0; count < max_count; count++) {
- rc = i2c_write(tpm_dev.bus, tpm_dev.addr, 0, 0,
- tpm_dev.buf, len + 1);
+ rc = i2c_write_raw(tpm_dev.bus, tpm_dev.addr,
+ tpm_dev.buf, len + 1);
if (rc == 0)
break; /* success, break to skip sleep */
diff --git a/src/drivers/maxim/max77686/max77686.c b/src/drivers/maxim/max77686/max77686.c
index adc1627430..e971dc504d 100644
--- a/src/drivers/maxim/max77686/max77686.c
+++ b/src/drivers/maxim/max77686/max77686.c
@@ -93,7 +93,7 @@ struct max77686_para max77686_param[] = {/*{vol_addr, vol_bitpos,
static inline int max77686_i2c_write(unsigned int bus, unsigned char chip_addr,
unsigned int reg, unsigned char val)
{
- return i2c_write(bus, chip_addr, reg, 1, &val, 1);
+ return i2c_writeb(bus, chip_addr, reg, val);
}
/*
@@ -107,7 +107,7 @@ static inline int max77686_i2c_write(unsigned int bus, unsigned char chip_addr,
static inline int max77686_i2c_read(unsigned int bus, unsigned char chip_addr,
unsigned int reg, unsigned char *val)
{
- return i2c_read(bus, chip_addr, reg, 1, val, 1);
+ return i2c_readb(bus, chip_addr, reg, (uint8_t *)val);
}
/*
diff --git a/src/drivers/parade/ps8625/ps8625.c b/src/drivers/parade/ps8625/ps8625.c
index 05219b0333..c673d3a3a5 100644
--- a/src/drivers/parade/ps8625/ps8625.c
+++ b/src/drivers/parade/ps8625/ps8625.c
@@ -31,7 +31,6 @@ void parade_ps8625_bridge_setup(unsigned bus, unsigned chip_base,
for (i = 0; i < parade_write_count; i++) {
const struct parade_write *w = &parade_writes[i];
- i2c_write(bus, chip_base + w->offset, w->reg, sizeof(w->reg),
- &w->val, sizeof(w->val));
+ i2c_writeb(bus, chip_base + w->offset, w->reg, w->val);
}
}
diff --git a/src/drivers/ti/tps65090/tps65090.c b/src/drivers/ti/tps65090/tps65090.c
index 653d20da24..35a050f36f 100644
--- a/src/drivers/ti/tps65090/tps65090.c
+++ b/src/drivers/ti/tps65090/tps65090.c
@@ -64,7 +64,7 @@ static int tps65090_i2c_write(unsigned int bus,
{
int ret;
- ret = i2c_write(bus, TPS65090_I2C_ADDR, reg_addr, 1, &value, 1);
+ ret = i2c_writeb(bus, TPS65090_I2C_ADDR, reg_addr, value);
printk(BIOS_DEBUG, "%s: reg=%#x, value=%#x, ret=%d\n",
__func__, reg_addr, value, ret);
return ret;
@@ -76,7 +76,7 @@ static int tps65090_i2c_read(unsigned int bus,
int ret;
printk(BIOS_DEBUG, "%s: reg=%#x, ", __func__, reg_addr);
- ret = i2c_read(bus, TPS65090_I2C_ADDR, reg_addr, 1, value, 1);
+ ret = i2c_readb(bus, TPS65090_I2C_ADDR, reg_addr, value);
if (ret)
printk(BIOS_DEBUG, "fail, ret=%d\n", ret);
else
diff --git a/src/drivers/xpowers/axp209/axp209.c b/src/drivers/xpowers/axp209/axp209.c
index 4f984e6b51..8aafd48ef0 100644
--- a/src/drivers/xpowers/axp209/axp209.c
+++ b/src/drivers/xpowers/axp209/axp209.c
@@ -47,12 +47,12 @@ enum registers {
*/
static int axp209_read(u8 bus, u8 reg, u8 *val)
{
- return i2c_read(bus, AXP209_I2C_ADDR, reg, 1, val, 1);
+ return i2c_readb(bus, AXP209_I2C_ADDR, reg, val);
}
static int axp209_write(u8 bus, u8 reg, u8 val)
{
- return i2c_write(bus, AXP209_I2C_ADDR, reg, 1, &val, 1);
+ return i2c_writeb(bus, AXP209_I2C_ADDR, reg, val);
}
/**