summaryrefslogtreecommitdiffstats
path: root/src/soc/samsung/exynos5250
diff options
context:
space:
mode:
authorJes Klinke <jbk@google.com>2022-02-22 16:00:09 -0800
committerJulius Werner <jwerner@chromium.org>2022-03-15 22:06:27 +0000
commit19baa9d51e4f1b36473dc750735eb6e5345bebda (patch)
tree60aada7f006fd73797b5c566d704e2b0ed5b728f /src/soc/samsung/exynos5250
parentca82e6161af7a453b512f35dd695a98084a1d7cf (diff)
downloadcoreboot-19baa9d51e4f1b36473dc750735eb6e5345bebda.tar.gz
coreboot-19baa9d51e4f1b36473dc750735eb6e5345bebda.tar.bz2
coreboot-19baa9d51e4f1b36473dc750735eb6e5345bebda.zip
i2c: Add configurable I2C transfer timeout
This patch introduces CONFIG_I2C_TRANSFER_TIMEOUT_US, which controls how long to wait for an I2C devices to produce/accept all the data bytes in a single transfer. (The device can delay transfer by stretching the clock of the ack bit.) The default value of this new setting is 500ms. Existing code had timeouts anywhere from tens of milliseconds to a full second beween various drivers. Drivers can still have their own shorter timeouts for setup/communication with the I2C host controller (as opposed to transactions with I2C devices on the bus.) In general, the timeout is not meant to be reached except in situations where there is already serious problem with the boot, and serves to make sure that some useful diagnostic output is produced on the console. Change-Id: I6423122f32aad1dbcee0bfe240cdaa8cb512791f Signed-off-by: Jes B. Klinke <jbk@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/62278 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/soc/samsung/exynos5250')
-rw-r--r--src/soc/samsung/exynos5250/i2c.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/soc/samsung/exynos5250/i2c.c b/src/soc/samsung/exynos5250/i2c.c
index bc5570daad7f..5ce4c7d8146e 100644
--- a/src/soc/samsung/exynos5250/i2c.c
+++ b/src/soc/samsung/exynos5250/i2c.c
@@ -8,6 +8,9 @@
#include <soc/clk.h>
#include <soc/i2c.h>
#include <soc/periph.h>
+#include <timer.h>
+
+#define I2C_TIMEOUT_US (1000 * USECS_PER_MSEC)
struct __packed i2c_regs
{
@@ -119,9 +122,9 @@ static int i2c_got_ack(struct i2c_regs *regs)
return !(read8(&regs->stat) & I2cStatAck);
}
-static int i2c_wait_for_idle(struct i2c_regs *regs)
+static int i2c_wait_for_idle(struct i2c_regs *regs, int timeout_us)
{
- int timeout = 1000 * 100; // 1s.
+ int timeout = DIV_ROUND_UP(timeout_us, 10);
while (timeout--) {
if (!(read8(&regs->stat) & I2cStatBusy))
return 0;
@@ -131,9 +134,9 @@ static int i2c_wait_for_idle(struct i2c_regs *regs)
return 1;
}
-static int i2c_wait_for_int(struct i2c_regs *regs)
+static int i2c_wait_for_int(struct i2c_regs *regs, int timeout_us)
{
- int timeout = 1000 * 100; // 1s.
+ int timeout = DIV_ROUND_UP(timeout_us, 10);
while (timeout--) {
if (i2c_int_pending(regs))
return 0;
@@ -148,7 +151,7 @@ static int i2c_send_stop(struct i2c_regs *regs)
uint8_t mode = read8(&regs->stat) & (I2cStatModeMask);
write8(&regs->stat, mode | I2cStatEnable);
i2c_clear_int(regs);
- return i2c_wait_for_idle(regs);
+ return i2c_wait_for_idle(regs, I2C_TIMEOUT_US);
}
static int i2c_send_start(struct i2c_regs *regs, int read, int chip)
@@ -158,7 +161,7 @@ static int i2c_send_start(struct i2c_regs *regs, int read, int chip)
write8(&regs->stat, mode | I2cStatStartStop | I2cStatEnable);
i2c_clear_int(regs);
- if (i2c_wait_for_int(regs))
+ if (i2c_wait_for_int(regs, I2C_TIMEOUT_US))
return 1;
if (!i2c_got_ack(regs)) {
@@ -180,7 +183,7 @@ static int i2c_xmit_buf(struct i2c_regs *regs, uint8_t *data, int len)
write8(&regs->ds, data[i]);
i2c_clear_int(regs);
- if (i2c_wait_for_int(regs))
+ if (i2c_wait_for_int(regs, CONFIG_I2C_TRANSFER_TIMEOUT_US))
return 1;
if (!i2c_got_ack(regs)) {
@@ -204,7 +207,7 @@ static int i2c_recv_buf(struct i2c_regs *regs, uint8_t *data, int len)
i2c_ack_disable(regs);
i2c_clear_int(regs);
- if (i2c_wait_for_int(regs))
+ if (i2c_wait_for_int(regs, CONFIG_I2C_TRANSFER_TIMEOUT_US))
return 1;
data[i] = read8(&regs->ds);
@@ -220,7 +223,7 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
struct i2c_regs *regs = i2c->regs;
int res = 0;
- if (!regs || i2c_wait_for_idle(regs))
+ if (!regs || i2c_wait_for_idle(regs, I2C_TIMEOUT_US))
return 1;
write8(&regs->stat, I2cStatMasterXmit | I2cStatEnable);