From: Caleb James DeLisle <cjd@cjdns.fr>
To: linux-i2c@vger.kernel.org
Cc: sr@denx.de, andi.shyti@kernel.org, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Caleb James DeLisle <cjd@cjdns.fr>
Subject: [PATCH 1/2] i2c: mt7621: support big endian processors
Date: Thu, 19 Nov 2026 16:40:39 +0000 [thread overview]
Message-ID: <20261119164040.2400580-2-cjd@cjdns.fr> (raw)
In-Reply-To: <20261119164040.2400580-1-cjd@cjdns.fr>
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@cjdns.fr>
---
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
next prev parent reply other threads:[~2026-11-19 16:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 16:40 [PATCH 0/2] i2c: mt7621: enable for EcoNet devices Caleb James DeLisle
2026-11-19 16:40 ` Caleb James DeLisle [this message]
2026-11-19 16:40 ` [PATCH 2/2] " Caleb James DeLisle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119164040.2400580-2-cjd@cjdns.fr \
--to=cjd@cjdns.fr \
--cc=andi.shyti@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=sr@denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®