Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add fdtbus_gpio_{read, write}_raw, which tells the contro...



details:   https://anonhg.NetBSD.org/src/rev/9bddd93db067
branches:  trunk
changeset: 342455:9bddd93db067
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Dec 22 22:19:07 2015 +0000

description:
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.

diffstat:

 sys/arch/arm/nvidia/tegra_gpio.c   |  16 ++++++++--------
 sys/arch/arm/samsung/exynos_gpio.c |  16 ++++++++--------
 sys/dev/fdt/fdt_gpio.c             |  24 ++++++++++++++++++++----
 sys/dev/fdt/fdtvar.h               |   8 +++++---
 sys/dev/fdt/fixedregulator.c       |   8 ++++----
 5 files changed, 45 insertions(+), 27 deletions(-)

diffs (233 lines):

diff -r d0451f539ecb -r 9bddd93db067 sys/arch/arm/nvidia/tegra_gpio.c
--- a/sys/arch/arm/nvidia/tegra_gpio.c  Tue Dec 22 22:12:08 2015 +0000
+++ b/sys/arch/arm/nvidia/tegra_gpio.c  Tue Dec 22 22:19:07 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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_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 @@
 }
 
 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);
diff -r d0451f539ecb -r 9bddd93db067 sys/arch/arm/samsung/exynos_gpio.c
--- a/sys/arch/arm/samsung/exynos_gpio.c        Tue Dec 22 22:12:08 2015 +0000
+++ b/sys/arch/arm/samsung/exynos_gpio.c        Tue Dec 22 22:19:07 2015 +0000
@@ -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 @@
                                     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 @@
 }
 
 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 @@
                                 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,
diff -r d0451f539ecb -r 9bddd93db067 sys/dev/fdt/fdt_gpio.c
--- a/sys/dev/fdt/fdt_gpio.c    Tue Dec 22 22:12:08 2015 +0000
+++ b/sys/dev/fdt/fdt_gpio.c    Tue Dec 22 22:19:07 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 {
        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 @@
 {
        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);
+}
diff -r d0451f539ecb -r 9bddd93db067 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Tue Dec 22 22:12:08 2015 +0000
+++ b/sys/dev/fdt/fdtvar.h      Tue Dec 22 22:19:07 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -72,8 +72,8 @@
 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 @@
 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 *);
diff -r d0451f539ecb -r 9bddd93db067 sys/dev/fdt/fixedregulator.c
--- a/sys/dev/fdt/fixedregulator.c      Tue Dec 22 22:12:08 2015 +0000
+++ b/sys/dev/fdt/fixedregulator.c      Tue Dec 22 22:19:07 2015 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
                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;
                }
        }



Home | Main Index | Thread Index | Old Index