Actually, the local mutex is unnecesary; the i2c bus lock is held

across all register r/m/w cycles, so we can just piggy back on that.
(I misread the code previously.)
This commit is contained in:
thorpej 2019-12-23 19:20:18 +00:00
parent 6eb08ce9f8
commit 73bb0a73cc

View File

@ -1,4 +1,4 @@
/* $NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $ */
/* $NetBSD: max77620.c,v 1.8 2019/12/23 19:20:18 thorpej Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.7 2019/12/23 18:49:13 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: max77620.c,v 1.8 2019/12/23 19:20:18 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -58,13 +58,6 @@ struct max77620_softc {
i2c_tag_t sc_i2c;
i2c_addr_t sc_addr;
int sc_phandle;
/*
* Locking order:
*
* max77620 -> i2c
*/
kmutex_t sc_lock;
};
struct max77620_pin {
@ -115,7 +108,6 @@ max77620_gpio_config(struct max77620_softc *sc, int pin, int flags)
uint32_t gpio;
KASSERT(pin >= 0 && pin < MAX_GPIO_COUNT);
KASSERT(mutex_owned(&sc->sc_lock));
gpio = I2C_READ(sc, MAX_GPIO_REG(pin));
@ -170,11 +162,9 @@ max77620_gpio_acquire(device_t dev, const void *data, size_t len, int flags)
if (pin >= MAX_GPIO_COUNT)
return NULL;
mutex_enter(&sc->sc_lock);
I2C_LOCK(sc);
error = max77620_gpio_config(sc, pin, flags);
I2C_UNLOCK(sc);
mutex_exit(&sc->sc_lock);
if (error != 0) {
device_printf(dev, "bad pin %d config %#x\n", pin, flags);
@ -196,11 +186,9 @@ max77620_gpio_release(device_t dev, void *priv)
struct max77620_softc * const sc = device_private(dev);
struct max77620_pin *gpin = priv;
mutex_enter(&sc->sc_lock);
I2C_LOCK(sc);
max77620_gpio_config(sc, gpin->pin_num, GPIO_PIN_INPUT|GPIO_PIN_OPENDRAIN);
I2C_UNLOCK(sc);
mutex_exit(&sc->sc_lock);
kmem_free(gpin, sizeof(*gpin));
}
@ -245,7 +233,6 @@ max77620_gpio_write(device_t dev, void *priv, int val, bool raw)
if (!raw && gpin->pin_actlo)
val = !val;
mutex_enter(&sc->sc_lock);
I2C_LOCK(sc);
gpio = I2C_READ(sc, MAX_GPIO_REG(gpin->pin_num));
gpio &= ~MAX_GPIO_OUTPUT_VAL;
@ -257,7 +244,6 @@ max77620_gpio_write(device_t dev, void *priv, int val, bool raw)
#endif
I2C_WRITE(sc, MAX_GPIO_REG(gpin->pin_num), gpio);
I2C_UNLOCK(sc);
mutex_exit(&sc->sc_lock);
}
static struct fdtbus_gpio_controller_func max77620_gpio_funcs = {
@ -297,8 +283,6 @@ max77620_attach(device_t parent, device_t self, void *aux)
sc->sc_addr = ia->ia_addr;
sc->sc_phandle = ia->ia_cookie;
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
aprint_naive("\n");
aprint_normal(": MAX77620 Power Management IC\n");