git: 09624daf6485 - main - aw_rsb: Accept a write in a single message

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Tue, 10 Nov 2026 13:42:51 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=09624daf6485be05dee9d6110b0488589da06e20

commit 09624daf6485be05dee9d6110b0488589da06e20
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-10 08:34:49 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-10 13:42:44 +0000

    aw_rsb: Accept a write in a single message
    
    The driver only took a write as two messages, the offset and then the
    data.  A write on an I2C bus is a single message that starts with the
    register, which is how a driver that can be on I2C or on RSB, like
    axp81x, does it.  Split such a message into the two the controller
    needs.
    
    Tested on: A64
---
 sys/arm/allwinner/aw_rsb.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/sys/arm/allwinner/aw_rsb.c b/sys/arm/allwinner/aw_rsb.c
index 7ff4d754127b..5a20284a5f8e 100644
--- a/sys/arm/allwinner/aw_rsb.c
+++ b/sys/arm/allwinner/aw_rsb.c
@@ -273,6 +273,7 @@ static int
 rsb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 {
 	struct rsb_softc *sc;
+	struct iic_msg wrmsgs[2];
 	uint32_t daddr[2], data[2], dlen;
 	uint16_t device_addr;
 	uint8_t cmd;
@@ -280,6 +281,24 @@ rsb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 
 	sc = device_get_softc(dev);
 
+	/*
+	 * Also accept a write of the offset and of the data in a single
+	 * message, which is how a write is done on an I2C bus.
+	 */
+	if (nmsgs == 1 && (msgs[0].flags & IIC_M_RD) == 0 &&
+	    msgs[0].len >= 2) {
+		wrmsgs[0].slave = msgs[0].slave;
+		wrmsgs[0].flags = IIC_M_WR | IIC_M_NOSTOP;
+		wrmsgs[0].len = 1;
+		wrmsgs[0].buf = msgs[0].buf;
+		wrmsgs[1].slave = msgs[0].slave;
+		wrmsgs[1].flags = IIC_M_WR;
+		wrmsgs[1].len = msgs[0].len - 1;
+		wrmsgs[1].buf = msgs[0].buf + 1;
+		msgs = wrmsgs;
+		nmsgs = 2;
+	}
+
 	/*
 	 * P2WI and RSB are not really I2C or SMBus controllers, so there are
 	 * some restrictions imposed by the driver.
@@ -288,7 +307,8 @@ rsb_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 	 * a write, containing a single data byte offset. Data will either
 	 * be read from or written to the corresponding data byte in the
 	 * second message. The slave address in both messages must be the
-	 * same.
+	 * same. A write can also be a single message, the first byte is the
+	 * offset.
 	 */
 	if (nmsgs != 2 || (msgs[0].flags & IIC_M_RD) == IIC_M_RD ||
 	    (msgs[0].slave >> 1) != (msgs[1].slave >> 1) ||