Source-Changes-HG archive

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

[src/trunk]: src/sys Implement subroutines for parsing out some of the generi...



details:   https://anonhg.NetBSD.org/src/rev/3ef8e381c2ed
branches:  trunk
changeset: 447763:3ef8e381c2ed
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Jan 23 04:21:54 2019 +0000

description:
Implement subroutines for parsing out some of the generic properties
specified in the pinctrl bindings, and adapt Meson, Rockchip, and
Allwinner pinctrl back-ends to use them.

Ok jmcneill@

diffstat:

 sys/arch/arm/amlogic/meson_pinctrl.c |    9 +-
 sys/arch/arm/rockchip/rk3328_iomux.c |   67 ++++++-----
 sys/arch/arm/rockchip/rk3399_iomux.c |   37 +++---
 sys/arch/arm/sunxi/sunxi_gpio.c      |   32 ++---
 sys/dev/fdt/fdt_pinctrl.c            |  195 ++++++++++++++++++++++++++++++++++-
 sys/dev/fdt/fdtvar.h                 |   11 +-
 6 files changed, 276 insertions(+), 75 deletions(-)

diffs (truncated from 515 to 300 lines):

diff -r a016927bee78 -r 3ef8e381c2ed sys/arch/arm/amlogic/meson_pinctrl.c
--- a/sys/arch/arm/amlogic/meson_pinctrl.c      Wed Jan 23 03:38:26 2019 +0000
+++ b/sys/arch/arm/amlogic/meson_pinctrl.c      Wed Jan 23 04:21:54 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: meson_pinctrl.c,v 1.1 2019/01/19 20:56:03 jmcneill Exp $ */
+/* $NetBSD: meson_pinctrl.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_soc.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: meson_pinctrl.c,v 1.1 2019/01/19 20:56:03 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: meson_pinctrl.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -170,10 +170,9 @@
        if (mux == -1)
                return -1;
 
-       groups_len = OF_getproplen(mux, "groups");
-       if (groups_len <= 0)
+       groups = fdtbus_pinctrl_parse_groups(mux, &groups_len);
+       if (groups == NULL)
                return -1;
-       groups = fdtbus_get_string(mux, "groups");
 
        for (; groups_len > 0;
            groups_len -= strlen(groups) + 1, groups += strlen(groups) + 1) {
diff -r a016927bee78 -r 3ef8e381c2ed sys/arch/arm/rockchip/rk3328_iomux.c
--- a/sys/arch/arm/rockchip/rk3328_iomux.c      Wed Jan 23 03:38:26 2019 +0000
+++ b/sys/arch/arm/rockchip/rk3328_iomux.c      Wed Jan 23 04:21:54 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk3328_iomux.c,v 1.1 2018/08/12 16:48:04 jmcneill Exp $ */
+/* $NetBSD: rk3328_iomux.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk3328_iomux.c,v 1.1 2018/08/12 16:48:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk3328_iomux.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -190,42 +190,49 @@
 static int
 rk3328_iomux_config(struct rk3328_iomux_softc *sc, const int phandle, u_int bank, u_int idx, u_int mux)
 {
-       u_int drv;
 
-       if (of_hasprop(phandle, "bias-disable"))
+       const int bias = fdtbus_pinctrl_parse_bias(phandle, NULL);
+       switch (bias) {
+       case 0:
                rk3328_iomux_set_bias(sc, bank, idx, GRF_GPIO_P_CTL_Z);
-       else if (of_hasprop(phandle, "bias-pull-up"))
+               break;
+       case GPIO_PIN_PULLUP:
                rk3328_iomux_set_bias(sc, bank, idx, GRF_GPIO_P_CTL_PULLUP);
-       else if (of_hasprop(phandle, "bias-pull-down"))
+               break;
+       case GPIO_PIN_PULLDOWN:
                rk3328_iomux_set_bias(sc, bank, idx, GRF_GPIO_P_CTL_PULLDOWN);
+               break;
+       }
 
-       if (of_getprop_uint32(phandle, "drive-strength", &drv) == 0) {
-               switch (drv) {
-               case 2:
-                       rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_2MA);
-                       break;
-               case 4:
-                       rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_4MA);
-                       break;
-               case 8:
-                       rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_8MA);
-                       break;
-               case 12:
-                       rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_12MA);
-                       break;
-               default:
-                       aprint_error_dev(sc->sc_dev, "unsupported drive-strength %u\n", drv);
-                       return EINVAL;
-               }
+       const int drv = fdtbus_pinctrl_parse_drive_strength(phandle);
+       switch (drv) {
+       case -1:
+               break;
+       case 2:
+               rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_2MA);
+               break;
+       case 4:
+               rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_4MA);
+               break;
+       case 8:
+               rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_8MA);
+               break;
+       case 12:
+               rk3328_iomux_set_drive_strength(sc, bank, idx, GRF_GPIO_E_CTL_12MA);
+               break;
+       default:
+               aprint_error_dev(sc->sc_dev, "unsupported drive-strength %u\n", drv);
+               return EINVAL;
        }
 
 #if notyet
-       if (of_hasprop(phandle, "input-enable"))
-               rk3328_iomux_set_direction(sc, bank, idx, GPIO_PIN_INPUT, -1);
-       else if (of_hasprop(phandle, "output-high"))
-               rk3328_iomux_set_direction(sc, bank, idx, GPIO_PIN_OUTPUT, GPIO_PIN_HIGH);
-       else if (of_hasprop(phandle, "output-low"))
-               rk3328_iomux_set_direction(sc, bank, idx, GPIO_PIN_OUTPUT, GPIO_PIN_LOW);
+       int output_value;
+       const int direction =
+           fdtbus_pinctrl_parse_input_output(phandle, &output_value);
+       if (direction != -1) {
+               rk3328_iomux_set_direction(sc, bank, idx, direction,
+                   output_value);
+       }
 #endif
 
        rk3328_iomux_set_mux(sc, bank, idx, mux);
diff -r a016927bee78 -r 3ef8e381c2ed sys/arch/arm/rockchip/rk3399_iomux.c
--- a/sys/arch/arm/rockchip/rk3399_iomux.c      Wed Jan 23 03:38:26 2019 +0000
+++ b/sys/arch/arm/rockchip/rk3399_iomux.c      Wed Jan 23 04:21:54 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk3399_iomux.c,v 1.1 2018/08/12 16:48:05 jmcneill Exp $ */
+/* $NetBSD: rk3399_iomux.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 //#define RK3399_IOMUX_DEBUG
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk3399_iomux.c,v 1.1 2018/08/12 16:48:05 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk3399_iomux.c,v 1.2 2019/01/23 04:21:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -348,27 +348,24 @@
 static int
 rk3399_iomux_config(struct rk3399_iomux_softc *sc, const int phandle, u_int bank, u_int idx, u_int mux)
 {
-       u_int drv;
+
+       const int bias = fdtbus_pinctrl_parse_bias(phandle, NULL);
+       if (bias != -1)
+               rk3399_iomux_set_bias(sc, bank, idx, bias);
 
-       if (of_hasprop(phandle, "bias-disable"))
-               rk3399_iomux_set_bias(sc, bank, idx, 0);
-       else if (of_hasprop(phandle, "bias-pull-up"))
-               rk3399_iomux_set_bias(sc, bank, idx, GPIO_PIN_PULLUP);
-       else if (of_hasprop(phandle, "bias-pull-down"))
-               rk3399_iomux_set_bias(sc, bank, idx, GPIO_PIN_PULLDOWN);
-
-       if (of_getprop_uint32(phandle, "drive-strength", &drv) == 0) {
-               if (rk3399_iomux_set_drive_strength(sc, bank, idx, drv) != 0)
-                       return EINVAL;
-       }
+       const int drv = fdtbus_pinctrl_parse_drive_strength(phandle);
+       if (drv != -1 &&
+           rk3399_iomux_set_drive_strength(sc, bank, idx, drv) != 0)
+               return EINVAL;
 
 #if notyet
-       if (of_hasprop(phandle, "input-enable"))
-               rk3399_iomux_set_direction(sc, bank, idx, GPIO_PIN_INPUT, -1);
-       else if (of_hasprop(phandle, "output-high"))
-               rk3399_iomux_set_direction(sc, bank, idx, GPIO_PIN_OUTPUT, GPIO_PIN_HIGH);
-       else if (of_hasprop(phandle, "output-low"))
-               rk3399_iomux_set_direction(sc, bank, idx, GPIO_PIN_OUTPUT, GPIO_PIN_LOW);
+       int output_value;
+       const int direction =
+           fdtbus_pinctrl_parse_input_output(phandle, &output_value);
+       if (direction != -1) {
+               rk3399_iomux_set_direction(sc, bank, idx, direction,
+                   output_value);
+       }
 #endif
 
        rk3399_iomux_set_mux(sc, bank, idx, mux);
diff -r a016927bee78 -r 3ef8e381c2ed sys/arch/arm/sunxi/sunxi_gpio.c
--- a/sys/arch/arm/sunxi/sunxi_gpio.c   Wed Jan 23 03:38:26 2019 +0000
+++ b/sys/arch/arm/sunxi/sunxi_gpio.c   Wed Jan 23 04:21:54 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gpio.c,v 1.21 2018/05/31 20:52:53 jmcneill Exp $ */
+/* $NetBSD: sunxi_gpio.c,v 1.22 2019/01/23 04:21:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_soc.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.21 2018/05/31 20:52:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.22 2019/01/23 04:21:54 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -582,7 +582,7 @@
 {
        const char *function;
 
-       function = fdtbus_get_string(phandle, "function");
+       function = fdtbus_pinctrl_parse_function(phandle);
        if (function != NULL)
                return function;
 
@@ -592,13 +592,12 @@
 static const char *
 sunxi_pinctrl_parse_pins(int phandle, int *pins_len)
 {
+       const char *pins;
        int len;
 
-       len = OF_getproplen(phandle, "pins");
-       if (len > 0) {
-               *pins_len = len;
-               return fdtbus_get_string(phandle, "pins");
-       }
+       pins = fdtbus_pinctrl_parse_pins(phandle, pins_len);
+       if (pins != NULL)
+               return pins;
 
        len = OF_getproplen(phandle, "allwinner,pins");
        if (len > 0) {
@@ -613,15 +612,13 @@
 sunxi_pinctrl_parse_bias(int phandle)
 {
        u_int pull;
-       int bias = -1;
+       int bias;
 
-       if (of_hasprop(phandle, "bias-disable"))
-               bias = 0;
-       else if (of_hasprop(phandle, "bias-pull-up"))
-               bias = GPIO_PIN_PULLUP;
-       else if (of_hasprop(phandle, "bias-pull-down"))
-               bias = GPIO_PIN_PULLDOWN;
-       else if (of_getprop_uint32(phandle, "allwinner,pull", &pull) == 0) {
+       bias = fdtbus_pinctrl_parse_bias(phandle, NULL);
+       if (bias != -1)
+               return bias;
+
+       if (of_getprop_uint32(phandle, "allwinner,pull", &pull) == 0) {
                switch (pull) {
                case 0:
                        bias = 0;
@@ -643,7 +640,8 @@
 {
        int val;
 
-       if (of_getprop_uint32(phandle, "drive-strength", &val) == 0)
+       val = fdtbus_pinctrl_parse_drive_strength(phandle);
+       if (val != -1)
                return val;
 
        if (of_getprop_uint32(phandle, "allwinner,drive", &val) == 0)
diff -r a016927bee78 -r 3ef8e381c2ed sys/dev/fdt/fdt_pinctrl.c
--- a/sys/dev/fdt/fdt_pinctrl.c Wed Jan 23 03:38:26 2019 +0000
+++ b/sys/dev/fdt/fdt_pinctrl.c Wed Jan 23 04:21:54 2019 +0000
@@ -1,6 +1,7 @@
-/* $NetBSD: fdt_pinctrl.c,v 1.6 2019/01/14 12:23:53 mlelstv Exp $ */
+/* $NetBSD: fdt_pinctrl.c,v 1.7 2019/01/23 04:23:01 thorpej Exp $ */
 
 /*-
+ * Copyright (c) 2019 Jason R. Thorpe
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
  * Copyright (c) 2015 Martin Fouts
  * All rights reserved.
@@ -28,10 +29,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.6 2019/01/14 12:23:53 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.7 2019/01/23 04:23:01 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
+#include <sys/gpio.h>
 #include <sys/kmem.h>
 #include <sys/queue.h>
 
@@ -166,3 +168,192 @@
 {
        fdtbus_pinctrl_configure_node(OF_finddevice("/"));
 }
+
+/*
+ * Helper routines for parsing put properties related to pinctrl bindings.
+ */
+
+/*



Home | Main Index | Thread Index | Old Index