Module Name:    src
Committed By:   thorpej
Date:           Mon Dec 23 19:20:18 UTC 2019

Modified Files:
        src/sys/dev/i2c: max77620.c

Log Message:
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.)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/i2c/max77620.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/max77620.c
diff -u src/sys/dev/i2c/max77620.c:1.7 src/sys/dev/i2c/max77620.c:1.8
--- src/sys/dev/i2c/max77620.c:1.7	Mon Dec 23 18:49:13 2019
+++ src/sys/dev/i2c/max77620.c	Mon Dec 23 19:20:18 2019
@@ -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 <jmcne...@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_sof
 	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, cons
 	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
 	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 *
 	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 *
 #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_
 	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");
 

Reply via email to