[PATCH 1/2] i2c: mt7621: support big endian processors
From: Caleb James DeLisle
Date: Thu Nov 19 2026 - 11:41:12 EST
Data is copied to and from I2C by way of a pair of IOMEM registers.
When sending, the data is copied to an intermediare buffer and then
written to the registers. However, the data is nominally little endian
but the registers are in CPU byte order. Make the buffer explicitly
little endian and use little endian read/write to support I2C on big
endian CPUs.
Signed-off-by: Caleb James DeLisle <cjd@xxxxxxxx>
---
drivers/i2c/busses/i2c-mt7621.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 826abb9252e31..c79a47b293ef4 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -185,7 +185,8 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
/* transfer data */
for (len = pmsg->len, j = 0; len > 0; len -= 8, j += 8) {
- u32 data[2] = { };
+ __le32 data[2] = { };
+ u32 val;
page_len = (len >= 8) ? 8 : len;
@@ -194,9 +195,12 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
SM0CTL1_READ : SM0CTL1_READ_LAST;
} else {
memcpy(data, &pmsg->buf[j], page_len);
- iowrite32(data[0], i2c->base + REG_SM0D0_REG);
- if (page_len > 4)
- iowrite32(data[1], i2c->base + REG_SM0D1_REG);
+ val = le32_to_cpu(data[0]);
+ iowrite32(val, i2c->base + REG_SM0D0_REG);
+ if (page_len > 4) {
+ val = le32_to_cpu(data[1]);
+ iowrite32(val, i2c->base + REG_SM0D1_REG);
+ }
cmd = SM0CTL1_WRITE;
}
@@ -205,9 +209,12 @@ static int mtk_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
goto err_timeout;
if (pmsg->flags & I2C_M_RD) {
- data[0] = ioread32(i2c->base + REG_SM0D0_REG);
- if (page_len > 4)
- data[1] = ioread32(i2c->base + REG_SM0D1_REG);
+ val = ioread32(i2c->base + REG_SM0D0_REG);
+ data[0] = cpu_to_le32(val);
+ if (page_len > 4) {
+ val = ioread32(i2c->base + REG_SM0D1_REG);
+ data[1] = cpu_to_le32(val);
+ }
memcpy(&pmsg->buf[j], data, page_len);
} else {
if (!(pmsg->flags & I2C_M_IGNORE_NAK)) {
--
2.39.5