summaryrefslogtreecommitdiff
path: root/src/soc
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc')
-rw-r--r--src/soc/broadcom/cygnus/i2c.c18
-rw-r--r--src/soc/intel/common/block/i2c/lpss_i2c.c19
-rw-r--r--src/soc/intel/quark/i2c.c16
-rw-r--r--src/soc/mediatek/mt8173/i2c.c23
-rw-r--r--src/soc/nvidia/tegra/i2c.c9
-rw-r--r--src/soc/qualcomm/ipq40xx/i2c.c11
-rw-r--r--src/soc/qualcomm/ipq806x/i2c.c11
-rw-r--r--src/soc/rockchip/common/i2c.c17
-rw-r--r--src/soc/samsung/exynos5250/i2c.c9
-rw-r--r--src/soc/samsung/exynos5420/i2c.c17
10 files changed, 83 insertions, 67 deletions
diff --git a/src/soc/broadcom/cygnus/i2c.c b/src/soc/broadcom/cygnus/i2c.c
index fe14000ce9..bc43a8886f 100644
--- a/src/soc/broadcom/cygnus/i2c.c
+++ b/src/soc/broadcom/cygnus/i2c.c
@@ -103,13 +103,14 @@ static void i2c_flush_fifo(struct cygnus_i2c_regs *reg_addr)
I2C_MASTER_RX_FIFO_FLUSH | I2C_MASTER_TX_FIFO_FLUSH);
}
-static int i2c_write(struct cygnus_i2c_regs *reg_addr, struct i2c_seg *segment)
+static int i2c_write(struct cygnus_i2c_regs *reg_addr,
+ struct i2c_msg *segment)
{
uint8_t *data = segment->buf;
unsigned int val, status;
int i, ret;
- write32(&reg_addr->i2c_master_data_wr, segment->chip << 1);
+ write32(&reg_addr->i2c_master_data_wr, segment->slave << 1);
for (i = 0; i < segment->len; i++) {
val = data[i];
@@ -150,13 +151,13 @@ flush_fifo:
return ret;
}
-static int i2c_read(struct cygnus_i2c_regs *reg_addr, struct i2c_seg *segment)
+static int i2c_read(struct cygnus_i2c_regs *reg_addr, struct i2c_msg *segment)
{
uint8_t *data = segment->buf;
int i, ret;
unsigned int status;
- write32(&reg_addr->i2c_master_data_wr, segment->chip << 1 | 1);
+ write32(&reg_addr->i2c_master_data_wr, segment->slave << 1 | 1);
/*
* Now we can activate the transfer. Specify the number of bytes to read
@@ -190,7 +191,7 @@ flush_fifo:
}
static int i2c_do_xfer(struct cygnus_i2c_regs *reg_addr,
- struct i2c_seg *segment)
+ struct i2c_msg *segment)
{
int ret;
@@ -206,7 +207,7 @@ static int i2c_do_xfer(struct cygnus_i2c_regs *reg_addr,
return EBUSY;
}
- if (segment->read)
+ if (segment->flags & I2C_M_RD)
ret = i2c_read(reg_addr, segment);
else
ret = i2c_write(reg_addr, segment);
@@ -214,12 +215,13 @@ static int i2c_do_xfer(struct cygnus_i2c_regs *reg_addr,
return ret;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
int i;
int res = 0;
struct cygnus_i2c_regs *regs = i2c_bus[bus];
- struct i2c_seg *seg = segments;
+ struct i2c_msg *seg = segments;
for (i = 0; i < seg_count; i++, seg++) {
res = i2c_do_xfer(regs, seg);
diff --git a/src/soc/intel/common/block/i2c/lpss_i2c.c b/src/soc/intel/common/block/i2c/lpss_i2c.c
index 5b188f8c22..711517f6d3 100644
--- a/src/soc/intel/common/block/i2c/lpss_i2c.c
+++ b/src/soc/intel/common/block/i2c/lpss_i2c.c
@@ -258,7 +258,7 @@ static int lpss_i2c_wait_for_bus_idle(struct lpss_i2c_regs *regs)
/* Transfer one byte of one segment, sending stop bit if requested */
static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
- struct i2c_seg *segment,
+ struct i2c_msg *segment,
size_t byte, int send_stop)
{
struct stopwatch sw;
@@ -266,7 +266,7 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
stopwatch_init_usecs_expire(&sw, LPSS_I2C_TIMEOUT_US);
- if (!segment->read) {
+ if (!(segment->flags & I2C_M_RD)) {
/* Write op only: Wait for FIFO not full */
while (!(read32(&regs->status) & STATUS_TX_FIFO_NOT_FULL)) {
if (stopwatch_expired(&sw)) {
@@ -283,7 +283,7 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
write32(&regs->cmd_data, cmd);
- if (segment->read) {
+ if (segment->flags & I2C_M_RD) {
/* Read op only: Wait for FIFO data and store it */
while (!(read32(&regs->status) & STATUS_RX_FIFO_NOT_EMPTY)) {
if (stopwatch_expired(&sw)) {
@@ -298,7 +298,8 @@ static int lpss_i2c_transfer_byte(struct lpss_i2c_regs *regs,
}
/* Global I2C bus handler, defined in include/i2c.h */
-int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
+int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments,
+ int count)
{
struct stopwatch sw;
struct lpss_i2c_regs *regs;
@@ -325,11 +326,12 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
while (count--) {
if (CONFIG_SOC_INTEL_COMMON_LPSS_I2C_DEBUG)
printk(BIOS_DEBUG, "i2c %u:%02x %s %d bytes : ",
- bus, segments->chip, segments->read ? "R" : "W",
+ bus, segments->slave,
+ (segments->flags & I2C_M_RD) ? "R" : "W",
segments->len);
/* Set target slave address */
- write32(&regs->target_addr, segments->chip);
+ write32(&regs->target_addr, segments->slave);
/* Read or write each byte in segment */
for (byte = 0; byte < segments->len; byte++) {
@@ -341,8 +343,9 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segments, int count)
if (lpss_i2c_transfer_byte(regs, segments, byte,
count == 0) < 0) {
printk(BIOS_ERR, "I2C %s failed: bus %u "
- "addr 0x%02x\n", segments->read ?
- "read" : "write", bus, segments->chip);
+ "addr 0x%02x\n",
+ (segments->flags & I2C_M_RD) ?
+ "read" : "write", bus, segments->slave);
goto out;
}
}
diff --git a/src/soc/intel/quark/i2c.c b/src/soc/intel/quark/i2c.c
index 26017389b8..e8dba5376f 100644
--- a/src/soc/intel/quark/i2c.c
+++ b/src/soc/intel/quark/i2c.c
@@ -186,8 +186,8 @@ static int platform_i2c_read(uint32_t restart, uint8_t *rx_buffer, int length,
return bytes_transferred;
}
-int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
- int seg_count)
+int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segment,
+ int seg_count)
{
int bytes_transferred;
uint8_t chip;
@@ -212,9 +212,9 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
printk(BIOS_ERR,
"I2C segment[%d]: %s 0x%02x %s 0x%p, 0x%08x bytes\n",
index,
- segment[index].read ? "Read from" : "Write to",
- segment[index].chip,
- segment[index].read ? "to " : "from",
+ (segment[index].flags & I2C_M_RD) ? "Read from" : "Write to",
+ segment[index].slave,
+ (segment[index].flags & I2C_M_RD) ? "to " : "from",
segment[index].buf,
segment[index].len);
printk(BIOS_ERR, "I2C %s\n",
@@ -243,7 +243,7 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
regs->ic_con = cmd;
/* Set the target chip address */
- chip = segment->chip;
+ chip = segment->slave;
regs->ic_tar = chip;
/* Enable the I2C controller */
@@ -270,13 +270,13 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_seg *segment,
total_bytes += length;
ASSERT(segment->buf != NULL);
ASSERT(length >= 1);
- ASSERT(segment->chip == chip);
+ ASSERT(segment->slave == chip);
/* Determine if this is the last segment of the transaction */
stop = (index == seg_count) ? IC_DATA_CMD_STOP : 0;
/* Fill the FIFO with the necessary command bytes */
- if (segment->read) {
+ if (segment->flags & I2C_M_RD) {
/* Place read commands into the FIFO */
rx_buffer = segment->buf;
data_bytes = platform_i2c_read(restart, rx_buffer,
diff --git a/src/soc/mediatek/mt8173/i2c.c b/src/soc/mediatek/mt8173/i2c.c
index f07ffc92ab..1d541e5d0f 100644
--- a/src/soc/mediatek/mt8173/i2c.c
+++ b/src/soc/mediatek/mt8173/i2c.c
@@ -136,7 +136,7 @@ static inline void mtk_i2c_dump_info(uint8_t bus)
I2CLOG("addr address %x\n", (uint32_t)regs);
}
-static uint32_t mtk_i2c_transfer(uint8_t bus, struct i2c_seg *seg,
+static uint32_t mtk_i2c_transfer(uint8_t bus, struct i2c_msg *seg,
enum i2c_modes read)
{
uint32_t ret_code = I2C_OK;
@@ -154,7 +154,7 @@ static uint32_t mtk_i2c_transfer(uint8_t bus, struct i2c_seg *seg,
regs = i2c[bus].i2c_regs;
dma_regs = i2c[bus].i2c_dma_regs;
- addr = seg[0].chip;
+ addr = seg[0].slave;
switch (read) {
case I2C_WRITE_MODE:
@@ -305,26 +305,31 @@ static uint32_t mtk_i2c_transfer(uint8_t bus, struct i2c_seg *seg,
return ret_code;
}
-static uint8_t mtk_i2c_should_combine(struct i2c_seg *seg, int left_count)
+static uint8_t mtk_i2c_should_combine(struct i2c_msg *seg, int left_count)
{
- if (left_count >= 2 && seg[0].read == 0 && seg[1].read == 1 &&
- seg[0].chip == seg[1].chip)
+ if (left_count >= 2 &&
+ !(seg[0].flags & I2C_M_RD) &&
+ (seg[1].flags & I2C_M_RD) &&
+ seg[0].slave == seg[1].slave)
return 1;
else
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
int ret = 0;
int i;
int read;
for (i = 0; i < seg_count; i++) {
- if (mtk_i2c_should_combine(&segments[i], seg_count - i))
+ if (mtk_i2c_should_combine(&segments[i], seg_count - i)) {
read = I2C_WRITE_READ_MODE;
- else
- read = segments[i].read;
+ } else {
+ read = (segments[i].flags & I2C_M_RD) ?
+ I2C_READ_MODE : I2C_WRITE_MODE;
+ }
ret = mtk_i2c_transfer(bus, &segments[i], read);
diff --git a/src/soc/nvidia/tegra/i2c.c b/src/soc/nvidia/tegra/i2c.c
index 926b76854b..e371a9d30f 100644
--- a/src/soc/nvidia/tegra/i2c.c
+++ b/src/soc/nvidia/tegra/i2c.c
@@ -187,9 +187,9 @@ static int i2c_transfer_segment(unsigned bus, unsigned chip, int restart,
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments, int count)
{
- struct i2c_seg *seg = segments;
+ struct i2c_msg *seg = segments;
int i;
if (bus >= g_num_i2c_buses) {
@@ -199,8 +199,9 @@ int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count)
}
for (i = 0; i < count; seg++, i++) {
- if (i2c_transfer_segment(bus, seg->chip, i < count - 1,
- seg->read, seg->buf, seg->len))
+ if (i2c_transfer_segment(bus, seg->slave, i < count - 1,
+ seg->flags & I2C_M_RD,
+ seg->buf, seg->len))
return -1;
}
return 0;
diff --git a/src/soc/qualcomm/ipq40xx/i2c.c b/src/soc/qualcomm/ipq40xx/i2c.c
index 772bf8b631..0cffaacbb2 100644
--- a/src/soc/qualcomm/ipq40xx/i2c.c
+++ b/src/soc/qualcomm/ipq40xx/i2c.c
@@ -155,19 +155,20 @@ static int i2c_init(blsp_qup_id_t id)
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
- struct i2c_seg *seg = segments;
+ struct i2c_msg *seg = segments;
int ret = 0;
if (i2c_init(bus))
return 1;
while (!ret && seg_count--) {
- if (seg->read)
- ret = i2c_read(bus, seg->chip, seg->buf, seg->len);
+ if (seg->flags & I2C_M_RD)
+ ret = i2c_read(bus, seg->slave, seg->buf, seg->len);
else
- ret = i2c_write(bus, seg->chip, seg->buf, seg->len,
+ ret = i2c_write(bus, seg->slave, seg->buf, seg->len,
(seg_count ? 0 : 1));
seg++;
}
diff --git a/src/soc/qualcomm/ipq806x/i2c.c b/src/soc/qualcomm/ipq806x/i2c.c
index e121ae8496..009cb94c1f 100644
--- a/src/soc/qualcomm/ipq806x/i2c.c
+++ b/src/soc/qualcomm/ipq806x/i2c.c
@@ -142,19 +142,20 @@ static int i2c_init(unsigned bus)
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
- struct i2c_seg *seg = segments;
+ struct i2c_msg *seg = segments;
int ret = 0;
if (i2c_init(bus))
return 1;
while (!ret && seg_count--) {
- if (seg->read)
- ret = i2c_read(bus, seg->chip, seg->buf, seg->len);
+ if (seg->flags & I2C_M_RD)
+ ret = i2c_read(bus, seg->slave, seg->buf, seg->len);
else
- ret = i2c_write(bus, seg->chip, seg->buf, seg->len,
+ ret = i2c_write(bus, seg->slave, seg->buf, seg->len,
(seg_count ? 0 : 1));
seg++;
}
diff --git a/src/soc/rockchip/common/i2c.c b/src/soc/rockchip/common/i2c.c
index 032efda9b2..5847f1658f 100644
--- a/src/soc/rockchip/common/i2c.c
+++ b/src/soc/rockchip/common/i2c.c
@@ -124,7 +124,7 @@ static int i2c_send_stop(struct rk_i2c_regs *reg_addr)
return res;
}
-static int i2c_read(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
+static int i2c_read(struct rk_i2c_regs *reg_addr, struct i2c_msg segment)
{
int res = 0;
uint8_t *data = segment.buf;
@@ -136,7 +136,7 @@ static int i2c_read(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
unsigned int con = 0;
unsigned int i, j;
- write32(&reg_addr->i2c_mrxaddr, I2C_8BIT | segment.chip << 1 | 1);
+ write32(&reg_addr->i2c_mrxaddr, I2C_8BIT | segment.slave << 1 | 1);
write32(&reg_addr->i2c_mrxraddr, 0);
con = I2C_MODE_TRX | I2C_EN | I2C_ACT2NAK;
while (bytes_remaining) {
@@ -182,7 +182,7 @@ static int i2c_read(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
return res;
}
-static int i2c_write(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
+static int i2c_write(struct rk_i2c_regs *reg_addr, struct i2c_msg segment)
{
int res = 0;
uint8_t *data = segment.buf;
@@ -194,7 +194,7 @@ static int i2c_write(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
unsigned int j = 1;
u32 txdata = 0;
- txdata |= (segment.chip << 1);
+ txdata |= (segment.slave << 1);
while (bytes_remaining) {
bytes_transferred = MIN(bytes_remaining, 32);
words_transferred = ALIGN_UP(bytes_transferred, 4) / 4;
@@ -239,25 +239,26 @@ static int i2c_write(struct rk_i2c_regs *reg_addr, struct i2c_seg segment)
return res;
}
-static int i2c_do_xfer(void *reg_addr, struct i2c_seg segment)
+static int i2c_do_xfer(void *reg_addr, struct i2c_msg segment)
{
int res = 0;
if (i2c_send_start(reg_addr))
return I2C_TIMEOUT;
- if (segment.read)
+ if (segment.flags & I2C_M_RD)
res = i2c_read(reg_addr, segment);
else
res = i2c_write(reg_addr, segment);
return i2c_send_stop(reg_addr) || res;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
int i;
int res = 0;
struct rk_i2c_regs *regs = (struct rk_i2c_regs *)(i2c_bus[bus]);
- struct i2c_seg *seg = segments;
+ struct i2c_msg *seg = segments;
for (i = 0; i < seg_count; i++, seg++) {
res = i2c_do_xfer(regs, *seg);
diff --git a/src/soc/samsung/exynos5250/i2c.c b/src/soc/samsung/exynos5250/i2c.c
index 2f3f28fb2b..6319a10b34 100644
--- a/src/soc/samsung/exynos5250/i2c.c
+++ b/src/soc/samsung/exynos5250/i2c.c
@@ -234,7 +234,8 @@ static int i2c_recv_buf(struct i2c_regs *regs, uint8_t *data, int len)
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments,
+ int seg_count)
{
struct s3c24x0_i2c_bus *i2c = &i2c_busses[bus];
struct i2c_regs *regs = i2c->regs;
@@ -247,12 +248,12 @@ int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int seg_count)
int i;
for (i = 0; i < seg_count; i++) {
- struct i2c_seg *seg = &segments[i];
+ struct i2c_msg *seg = &segments[i];
- res = i2c_send_start(regs, seg->read, seg->chip);
+ res = i2c_send_start(regs, seg->flags & I2C_M_RD, seg->slave);
if (res)
break;
- if (seg->read)
+ if (seg->flags & I2C_M_RD)
res = i2c_recv_buf(regs, seg->buf, seg->len);
else
res = i2c_xmit_buf(regs, seg->buf, seg->len);
diff --git a/src/soc/samsung/exynos5420/i2c.c b/src/soc/samsung/exynos5420/i2c.c
index 9a9b197cc5..ae9560ffdd 100644
--- a/src/soc/samsung/exynos5420/i2c.c
+++ b/src/soc/samsung/exynos5420/i2c.c
@@ -445,11 +445,12 @@ static int hsi2c_recvdata(struct hsi2c_regs *regs, uint8_t *data, int len)
return len ? -1 : 0;
}
-static int hsi2c_segment(struct i2c_seg *seg, struct hsi2c_regs *regs, int stop)
+static int hsi2c_segment(struct i2c_msg *seg, struct hsi2c_regs *regs,
+ int stop)
{
const uint32_t usi_ctl = Hsi2cFuncModeI2c | Hsi2cMaster;
- write32(&regs->i2c_addr, HSI2C_SLV_ADDR_MAS(seg->chip));
+ write32(&regs->i2c_addr, HSI2C_SLV_ADDR_MAS(seg->slave));
/*
* We really only want to stop after this transaction (I think) if the
@@ -461,7 +462,7 @@ static int hsi2c_segment(struct i2c_seg *seg, struct hsi2c_regs *regs, int stop)
uint32_t autoconf =
seg->len | Hsi2cMasterRun | Hsi2cStopAfterTrans;
- if (seg->read) {
+ if (seg->flags & I2C_M_RD) {
write32(&regs->usi_ctl, usi_ctl | Hsi2cRxchon);
write32(&regs->i2c_auto_conf, autoconf | Hsi2cReadWrite);
@@ -482,7 +483,7 @@ static int hsi2c_segment(struct i2c_seg *seg, struct hsi2c_regs *regs, int stop)
return 0;
}
-static int hsi2c_transfer(struct i2c_bus *i2c, struct i2c_seg *segments,
+static int hsi2c_transfer(struct i2c_bus *i2c, struct i2c_msg *segments,
int count)
{
struct hsi2c_regs *regs = i2c->hsregs;
@@ -627,7 +628,7 @@ static int i2c_recv_buf(struct i2c_regs *regs, uint8_t *data, int len)
return 0;
}
-int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count)
+int platform_i2c_transfer(unsigned bus, struct i2c_msg *segments, int count)
{
struct i2c_bus *i2c = &i2c_busses[bus];
if (i2c->is_highspeed)
@@ -643,12 +644,12 @@ int platform_i2c_transfer(unsigned bus, struct i2c_seg *segments, int count)
int i;
for (i = 0; i < count; i++) {
- struct i2c_seg *seg = &segments[i];
+ struct i2c_msg *seg = &segments[i];
- res = i2c_send_start(regs, seg->read, seg->chip);
+ res = i2c_send_start(regs, seg->flags & I2C_M_RD, seg->slave);
if (res)
break;
- if (seg->read)
+ if (seg->flags & I2C_M_RD)
res = i2c_recv_buf(regs, seg->buf, seg->len);
else
res = i2c_xmit_buf(regs, seg->buf, seg->len);