Module Name: src
Committed By: jmcneill
Date: Wed Oct 17 16:56:40 UTC 2018
Modified Files:
src/sys/dev/i2c: tcakp.c
Log Message:
lock/unlock I2C bus around transfers as required by API
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/tcakp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/i2c/tcakp.c
diff -u src/sys/dev/i2c/tcakp.c:1.9 src/sys/dev/i2c/tcakp.c:1.10
--- src/sys/dev/i2c/tcakp.c:1.9 Tue Jun 26 06:03:57 2018
+++ src/sys/dev/i2c/tcakp.c Wed Oct 17 16:56:40 2018
@@ -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 <[email protected]>
@@ -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 @@ tcakp_attach(device_t parent, device_t s
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,
®, 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;
}