summaryrefslogtreecommitdiff
path: root/sys/dev/i2c
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2018-10-17 16:56:40 +0000
committerjmcneill <jmcneill@NetBSD.org>2018-10-17 16:56:40 +0000
commit39fde00fa1109e2abe2f504b81d80c7c2cd1a9f7 (patch)
tree15525beb0c21099b82d419690736d6d8eccc2d4e /sys/dev/i2c
parent13df4a9f9081f8f5aed5af95db63e2691adce166 (diff)
lock/unlock I2C bus around transfers as required by API
Diffstat (limited to 'sys/dev/i2c')
-rw-r--r--sys/dev/i2c/tcakp.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/dev/i2c/tcakp.c b/sys/dev/i2c/tcakp.c
index 8c5ee6ea830..ab654958331 100644
--- a/sys/dev/i2c/tcakp.c
+++ b/sys/dev/i2c/tcakp.c
@@ -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>
@@ -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 self, void *aux)
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;
}