Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c lock/unlock I2C bus around transfers as required...



details:   https://anonhg.NetBSD.org/src/rev/c0fbc29ce5ab
branches:  trunk
changeset: 445198:c0fbc29ce5ab
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Oct 17 16:56:40 2018 +0000

description:
lock/unlock I2C bus around transfers as required by API

diffstat:

 sys/dev/i2c/tcakp.c |  20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r ae9de765c59b -r c0fbc29ce5ab sys/dev/i2c/tcakp.c
--- a/sys/dev/i2c/tcakp.c       Wed Oct 17 06:19:21 2018 +0000
+++ b/sys/dev/i2c/tcakp.c       Wed Oct 17 16:56:40 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tcakp.c,v 1.9 2018/06/26 06:03:57 thorpej Exp $ */
+/* $NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_fdt.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.9 2018/06/26 06:03:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcakp.c,v 1.10 2018/10/17 16:56:40 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -364,14 +364,26 @@
 static int
 tcakp_read(struct tcakp_softc *sc, uint8_t reg, uint8_t *val)
 {
-       return iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr,
+       int error;
+
+       iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
+       error = iic_exec(sc->sc_i2c, I2C_OP_READ_WITH_STOP, sc->sc_addr,
            &reg, 1, val, 1, I2C_F_POLL);
+       iic_release_bus(sc->sc_i2c, I2C_F_POLL);
+
+       return error;
 }
 
 static int
 tcakp_write(struct tcakp_softc *sc, uint8_t reg, uint8_t val)
 {
        uint8_t buf[2] = { reg, val };
-       return iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr,
+       int error;
+
+       iic_acquire_bus(sc->sc_i2c, I2C_F_POLL);
+       error = iic_exec(sc->sc_i2c, I2C_OP_WRITE_WITH_STOP, sc->sc_addr,
            NULL, 0, buf, 2, I2C_F_POLL);
+       iic_release_bus(sc->sc_i2c, I2C_F_POLL);
+
+       return error;
 }



Home | Main Index | Thread Index | Old Index