Module Name:    src
Committed By:   jmcneill
Date:           Tue Dec 22 22:19:07 UTC 2015

Modified Files:
        src/sys/arch/arm/nvidia: tegra_gpio.c
        src/sys/arch/arm/samsung: exynos_gpio.c
        src/sys/dev/fdt: fdt_gpio.c fdtvar.h fixedregulator.c

Log Message:
Add fdtbus_gpio_{read,write}_raw, which tells the controller not to take
polarity into account. Tegra GPIO pin data includes pin polarity, but so
does a regulator-fixed node, so the end result was that the enable value
was being swapped twice. Change fregulator to use the raw APIs, and adapt
Tegra and Exynos GPIO drivers to support this flag.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/nvidia/tegra_gpio.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/samsung/exynos_gpio.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/fdt/fdt_gpio.c \
    src/sys/dev/fdt/fixedregulator.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/fdt/fdtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/nvidia/tegra_gpio.c
diff -u src/sys/arch/arm/nvidia/tegra_gpio.c:1.5 src/sys/arch/arm/nvidia/tegra_gpio.c:1.6
--- src/sys/arch/arm/nvidia/tegra_gpio.c:1.5	Mon Dec 14 20:57:34 2015
+++ src/sys/arch/arm/nvidia/tegra_gpio.c	Tue Dec 22 22:19:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_gpio.c,v 1.5 2015/12/14 20:57:34 jmcneill Exp $ */
+/* $NetBSD: tegra_gpio.c,v 1.6 2015/12/22 22:19:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_gpio.c,v 1.5 2015/12/14 20:57:34 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_gpio.c,v 1.6 2015/12/22 22:19:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -89,8 +89,8 @@ static void	tegra_gpio_attach(device_t, 
 static void *	tegra_gpio_fdt_acquire(device_t, const void *,
 		    size_t, int);
 static void	tegra_gpio_fdt_release(device_t, void *);
-static int	tegra_gpio_fdt_read(device_t, void *);
-static void	tegra_gpio_fdt_write(device_t, void *, int);
+static int	tegra_gpio_fdt_read(device_t, void *, bool);
+static void	tegra_gpio_fdt_write(device_t, void *, int, bool);
 
 struct fdtbus_gpio_controller_func tegra_gpio_funcs = {
 	.acquire = tegra_gpio_fdt_acquire,
@@ -323,25 +323,25 @@ tegra_gpio_fdt_release(device_t dev, voi
 }
 
 static int
-tegra_gpio_fdt_read(device_t dev, void *priv)
+tegra_gpio_fdt_read(device_t dev, void *priv, bool raw)
 {
 	struct tegra_gpio_pin *gpin = priv;
 	int val;
 
 	val = tegra_gpio_read(gpin);
 
-	if (gpin->pin_actlo)
+	if (!raw && gpin->pin_actlo)
 		val = !val;
 
 	return val;
 }
 
 static void
-tegra_gpio_fdt_write(device_t dev, void *priv, int val)
+tegra_gpio_fdt_write(device_t dev, void *priv, int val, bool raw)
 {
 	struct tegra_gpio_pin *gpin = priv;
 
-	if (gpin->pin_actlo)
+	if (!raw && gpin->pin_actlo)
 		val = !val;
 
 	tegra_gpio_write(gpin, val);

Index: src/sys/arch/arm/samsung/exynos_gpio.c
diff -u src/sys/arch/arm/samsung/exynos_gpio.c:1.16 src/sys/arch/arm/samsung/exynos_gpio.c:1.17
--- src/sys/arch/arm/samsung/exynos_gpio.c:1.16	Tue Dec 22 03:36:01 2015
+++ src/sys/arch/arm/samsung/exynos_gpio.c	Tue Dec 22 22:19:07 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: exynos_gpio.c,v 1.16 2015/12/22 03:36:01 marty Exp $ */
+/*	$NetBSD: exynos_gpio.c,v 1.17 2015/12/22 22:19:07 jmcneill Exp $ */
 
 /*-
 * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #include "gpio.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exynos_gpio.c,v 1.16 2015/12/22 03:36:01 marty Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exynos_gpio.c,v 1.17 2015/12/22 22:19:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -157,8 +157,8 @@ static void *exynos_gpio_fdt_acquire(dev
 				     size_t, int);
 static void exynos_gpio_fdt_release(device_t, void *);
 
-static int exynos_gpio_fdt_read(device_t, void *);
-static void exynos_gpio_fdt_write(device_t, void *, int);
+static int exynos_gpio_fdt_read(device_t, void *, bool);
+static void exynos_gpio_fdt_write(device_t, void *, int, bool);
 static struct exynos_gpio_bank *
 exynos_gpio_pin_lookup(const char *pinname, int *ppin);
 static int exynos_gpio_cfprint(void *, const char *);
@@ -393,7 +393,7 @@ exynos_gpio_fdt_release(device_t dev, vo
 }
 
 static int
-exynos_gpio_fdt_read(device_t dev, void *priv)
+exynos_gpio_fdt_read(device_t dev, void *priv, bool raw)
 {
 	struct exynos_gpio_pin *gpin = priv;
 	int val;
@@ -402,18 +402,18 @@ exynos_gpio_fdt_read(device_t dev, void 
 				 gpin->pin_sc->sc_bsh,
 				 EXYNOS_GPIO_DAT) >> gpin->pin_no) & 1;
 
-	if (gpin->pin_actlo)
+	if (!raw && gpin->pin_actlo)
 		val = !val;
 
 	return val;
 }
 
 static void
-exynos_gpio_fdt_write(device_t dev, void *priv, int val)
+exynos_gpio_fdt_write(device_t dev, void *priv, int val, bool raw)
 {
 	struct exynos_gpio_pin *gpin = priv;
 
-	if (gpin->pin_actlo)
+	if (!raw && gpin->pin_actlo)
 		val = !val;
 
 	val = bus_space_read_1(gpin->pin_sc->sc_bst,

Index: src/sys/dev/fdt/fdt_gpio.c
diff -u src/sys/dev/fdt/fdt_gpio.c:1.2 src/sys/dev/fdt/fdt_gpio.c:1.3
--- src/sys/dev/fdt/fdt_gpio.c:1.2	Wed Dec 16 12:17:45 2015
+++ src/sys/dev/fdt/fdt_gpio.c	Tue Dec 22 22:19:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_gpio.c,v 1.2 2015/12/16 12:17:45 jmcneill Exp $ */
+/* $NetBSD: fdt_gpio.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.2 2015/12/16 12:17:45 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -131,7 +131,7 @@ fdtbus_gpio_read(struct fdtbus_gpio_pin 
 {
 	struct fdtbus_gpio_controller *gc = gp->gp_gc;
 
-	return gc->gc_funcs->read(gc->gc_dev, gp->gp_priv);
+	return gc->gc_funcs->read(gc->gc_dev, gp->gp_priv, false);
 }
 
 void
@@ -139,5 +139,21 @@ fdtbus_gpio_write(struct fdtbus_gpio_pin
 {
 	struct fdtbus_gpio_controller *gc = gp->gp_gc;
 
-	gc->gc_funcs->write(gc->gc_dev, gp->gp_priv, val);
+	gc->gc_funcs->write(gc->gc_dev, gp->gp_priv, val, false);
+}
+
+int
+fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *gp)
+{
+	struct fdtbus_gpio_controller *gc = gp->gp_gc;
+
+	return gc->gc_funcs->read(gc->gc_dev, gp->gp_priv, true);
+}
+
+void
+fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *gp, int val)
+{
+	struct fdtbus_gpio_controller *gc = gp->gp_gc;
+
+	gc->gc_funcs->write(gc->gc_dev, gp->gp_priv, val, true);
 }
Index: src/sys/dev/fdt/fixedregulator.c
diff -u src/sys/dev/fdt/fixedregulator.c:1.2 src/sys/dev/fdt/fixedregulator.c:1.3
--- src/sys/dev/fdt/fixedregulator.c:1.2	Wed Dec 16 19:33:55 2015
+++ src/sys/dev/fdt/fixedregulator.c	Tue Dec 22 22:19:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: fixedregulator.c,v 1.2 2015/12/16 19:33:55 jmcneill Exp $ */
+/* $NetBSD: fixedregulator.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.2 2015/12/16 19:33:55 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fixedregulator.c,v 1.3 2015/12/22 22:19:07 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -133,14 +133,14 @@ fixedregulator_enable(device_t dev, bool
 		if (sc->sc_always_on) {
 			return 0;
 		} else {
-			fdtbus_gpio_write(sc->sc_pin, sc->sc_enable_val);
+			fdtbus_gpio_write_raw(sc->sc_pin, sc->sc_enable_val);
 			return 0;
 		}
 	} else {
 		if (sc->sc_always_on) {
 			return EIO;
 		} else {
-			fdtbus_gpio_write(sc->sc_pin, !sc->sc_enable_val);
+			fdtbus_gpio_write_raw(sc->sc_pin, !sc->sc_enable_val);
 			return 0;
 		}
 	}

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.3 src/sys/dev/fdt/fdtvar.h:1.4
--- src/sys/dev/fdt/fdtvar.h:1.3	Tue Dec 22 21:42:11 2015
+++ src/sys/dev/fdt/fdtvar.h	Tue Dec 22 22:19:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.3 2015/12/22 21:42:11 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.4 2015/12/22 22:19:07 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -72,8 +72,8 @@ struct fdtbus_gpio_pin {
 struct fdtbus_gpio_controller_func {
 	void *	(*acquire)(device_t, const void *, size_t, int);
 	void	(*release)(device_t, void *);
-	int	(*read)(device_t, void *);
-	void	(*write)(device_t, void *, int);
+	int	(*read)(device_t, void *, bool);
+	void	(*write)(device_t, void *, int, bool);
 };
 
 struct fdtbus_regulator_controller;
@@ -131,6 +131,8 @@ struct fdtbus_gpio_pin *fdtbus_gpio_acqu
 void		fdtbus_gpio_release(struct fdtbus_gpio_pin *);
 int		fdtbus_gpio_read(struct fdtbus_gpio_pin *);
 void		fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
+int		fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
+void		fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
 void		fdtbus_regulator_release(struct fdtbus_regulator *);
 int		fdtbus_regulator_enable(struct fdtbus_regulator *);

Reply via email to