git: 9a95029ea797 - stable/13 - rk_i2c: do not hide NACK condition from consumers

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Wed, 22 Dec 2021 06:51:30 UTC
The branch stable/13 has been updated by avg:

URL: https://cgit.FreeBSD.org/src/commit/?id=9a95029ea7975d755f02cddef5618a9f7e079694

commit 9a95029ea7975d755f02cddef5618a9f7e079694
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2021-12-15 08:59:22 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2021-12-22 06:49:15 +0000

    rk_i2c: do not hide NACK condition from consumers
    
    Previously the driver would happily talk to addresses with no device
    returning some garbage for reads and sending bits into the void for writes.
    
    (cherry picked from commit 4501b0707198e7ad1da792639a8b164f9380b95d)
---
 sys/arm64/rockchip/rk_i2c.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/arm64/rockchip/rk_i2c.c b/sys/arm64/rockchip/rk_i2c.c
index 171b28a8b617..2be6716af4eb 100644
--- a/sys/arm64/rockchip/rk_i2c.c
+++ b/sys/arm64/rockchip/rk_i2c.c
@@ -430,6 +430,7 @@ rk_i2c_start_xfer(struct rk_i2c_softc *sc, struct iic_msg *msg, boolean_t last)
 			    RK_I2C_IEN_NAKRCVIEN);
 		}
 	}
+	reg |= RK_I2C_CON_NAKSTOP;
 	reg |= sc->mode << RK_I2C_CON_MODE_SHIFT;
 	reg |= RK_I2C_CON_EN;
 	RK_I2C_WRITE(sc, RK_I2C_CON, reg);
@@ -549,6 +550,9 @@ rk_i2c_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 
 	sc->busy = 0;
 
+	if (sc->nak_recv)
+		err = IIC_ENOACK;
+
 	RK_I2C_UNLOCK(sc);
 	return (err);
 }