Skip to contentSkip to conversation

i2c: mt7621: enable for EcoNet devices

PATCH New Caleb James DeLisle 1 participant 3 messages Nov 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover i2c: mt7621: enable for EcoNet devices

Small patchset to fix an endianness bug in i2c-mt7621 and then enable building it when building EcoNet devices.

Caleb James DeLisle (2):
i2c: mt7621: support big endian processors
i2c: mt7621: enable for EcoNet devices

 drivers/i2c/busses/Kconfig      |  2 +-
 drivers/i2c/busses/i2c-mt7621.c | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

base-commit: e8017d29067fd1310a65c3494ce1a1b492adbac6

Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/2 i2c: mt7621: support big endian processors

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.

---
 drivers/i2c/busses/i2c-mt7621.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-mt7621.c +14 -7
index 826abb9252e31..c79a47b293ef4 100644
@@ -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)) {
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/2 i2c: mt7621: enable for EcoNet devices

In reply to Caleb James DeLisle

EcoNet EN751221 uses the same I2C subsystem as the MT7621, allow selection of this driver when building for EcoNet devices.

---
 drivers/i2c/busses/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/Kconfig +1 -1
index 275aaa7f35833..9295a35f4a181 100644
@@ -918,7 +918,7 @@ config I2C_MT65XX
 
 config I2C_MT7621
 	tristate "MT7621/MT7628 I2C Controller"
-	depends on (RALINK && (SOC_MT7620 || SOC_MT7621)) || ARCH_AIROHA || COMPILE_TEST
+	depends on (RALINK && (SOC_MT7620 || SOC_MT7621)) || ARCH_AIROHA || ECONET || COMPILE_TEST
 	help
 	  Say Y here to include support for I2C controller in the
 	  MediaTek MT7621/MT7628 SoCs.
Signature · 1 line
2.39.5