git: 2a36909a94be - main - iicoc: fix repeated start

From: Philip Paeps <philip_at_FreeBSD.org>
Date: Mon, 01 Nov 2021 05:09:25 UTC
The branch main has been updated by philip:

URL: https://cgit.FreeBSD.org/src/commit/?id=2a36909a94be110c34128319536c1c595635aa2e

commit 2a36909a94be110c34128319536c1c595635aa2e
Author:     Thomas Skibo <thomas-bsd@skibo.net>
AuthorDate: 2021-11-01 04:29:29 +0000
Commit:     Philip Paeps <philip@FreeBSD.org>
CommitDate: 2021-11-01 04:29:29 +0000

    iicoc: fix repeated start
    
    Reviewed by:    jrtc27, philip
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D32737
---
 sys/dev/iicbus/iicoc.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/sys/dev/iicbus/iicoc.c b/sys/dev/iicbus/iicoc.c
index e243e7128be7..f22878224c32 100644
--- a/sys/dev/iicbus/iicoc.c
+++ b/sys/dev/iicbus/iicoc.c
@@ -147,8 +147,8 @@ iicoc_init(device_t dev)
 	return ((value & OC_CONTROL_EN) == 0);
 }
 
-int
-iicoc_iicbus_start(device_t dev, u_char slave, int timeout)
+static int
+iicoc_iicbus_start_common(device_t dev, u_char slave, int timeout, bool repeat)
 {
 	int error = IIC_EBUSERR;
 	struct iicoc_softc *sc;
@@ -158,7 +158,7 @@ iicoc_iicbus_start(device_t dev, u_char slave, int timeout)
 	sc->i2cdev_addr = (slave >> 1);
 
 	/* Verify the bus is idle */
-	if (iicoc_wait_on_status(dev, OC_STATUS_BUSY) < 0)
+	if (!repeat && iicoc_wait_on_status(dev, OC_STATUS_BUSY) < 0)
 		goto i2c_stx_error;
 
 	/* Write Slave Address */
@@ -186,6 +186,20 @@ i2c_stx_error:
 	return (error);
 }
 
+int
+iicoc_iicbus_start(device_t dev, u_char slave, int timeout)
+{
+
+	return (iicoc_iicbus_start_common(dev, slave, timeout, false));
+}
+
+int
+iicoc_iicbus_repeated_start(device_t dev, u_char slave, int timeout)
+{
+
+	return (iicoc_iicbus_start_common(dev, slave, timeout, true));
+}
+
 int
 iicoc_iicbus_stop(device_t dev)
 {
@@ -268,10 +282,3 @@ iicoc_iicbus_reset(device_t dev, u_char speed, u_char addr, u_char *oldadr)
 	mtx_unlock(&sc->sc_mtx);
 	return (error);
 }
-
-int
-iicoc_iicbus_repeated_start(device_t dev, u_char slave, int timeout)
-{
-
-	return 0;
-}