git: 99f6b0e44073 - stable/12 - rk_i2c: do not hide NACK condition from consumers

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

URL: https://cgit.FreeBSD.org/src/commit/?id=99f6b0e44073656dbc6ea78f4522590843150777

commit 99f6b0e44073656dbc6ea78f4522590843150777
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:57:18 +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 078f0be52ec0..9158eb8222eb 100644
--- a/sys/arm64/rockchip/rk_i2c.c
+++ b/sys/arm64/rockchip/rk_i2c.c
@@ -432,6 +432,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);
@@ -551,6 +552,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);
 }