Module Name:    src
Committed By:   thorpej
Date:           Wed Jan 23 04:21:55 UTC 2019

Modified Files:
        src/sys/arch/arm/amlogic: meson_pinctrl.c
        src/sys/arch/arm/rockchip: rk3328_iomux.c rk3399_iomux.c
        src/sys/arch/arm/sunxi: sunxi_gpio.c
        src/sys/dev/fdt: fdtvar.h

Log Message:
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@


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/amlogic/meson_pinctrl.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/rockchip/rk3328_iomux.c \
    src/sys/arch/arm/rockchip/rk3399_iomux.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/arm/sunxi/sunxi_gpio.c
cvs rdiff -u -r1.45 -r1.46 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/amlogic/meson_pinctrl.c
diff -u src/sys/arch/arm/amlogic/meson_pinctrl.c:1.1 src/sys/arch/arm/amlogic/meson_pinctrl.c:1.2
--- src/sys/arch/arm/amlogic/meson_pinctrl.c:1.1	Sat Jan 19 20:56:03 2019
+++ src/sys/arch/arm/amlogic/meson_pinctrl.c	Wed Jan 23 04:21:54 2019
@@ -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 <[email protected]>
@@ -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 @@ meson_pinctrl_set_config(device_t dev, c
 	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) {

Index: src/sys/arch/arm/rockchip/rk3328_iomux.c
diff -u src/sys/arch/arm/rockchip/rk3328_iomux.c:1.1 src/sys/arch/arm/rockchip/rk3328_iomux.c:1.2
--- src/sys/arch/arm/rockchip/rk3328_iomux.c:1.1	Sun Aug 12 16:48:04 2018
+++ src/sys/arch/arm/rockchip/rk3328_iomux.c	Wed Jan 23 04:21:54 2019
@@ -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 <[email protected]>
@@ -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 @@ rk3328_iomux_set_mux(struct rk3328_iomux
 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);
Index: src/sys/arch/arm/rockchip/rk3399_iomux.c
diff -u src/sys/arch/arm/rockchip/rk3399_iomux.c:1.1 src/sys/arch/arm/rockchip/rk3399_iomux.c:1.2
--- src/sys/arch/arm/rockchip/rk3399_iomux.c:1.1	Sun Aug 12 16:48:05 2018
+++ src/sys/arch/arm/rockchip/rk3399_iomux.c	Wed Jan 23 04:21:54 2019
@@ -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 <[email protected]>
@@ -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 @@ rk3399_iomux_set_mux(struct rk3399_iomux
 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;
 
-	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 bias = fdtbus_pinctrl_parse_bias(phandle, NULL);
+	if (bias != -1)
+		rk3399_iomux_set_bias(sc, bank, idx, bias);
+
+	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);

Index: src/sys/arch/arm/sunxi/sunxi_gpio.c
diff -u src/sys/arch/arm/sunxi/sunxi_gpio.c:1.21 src/sys/arch/arm/sunxi/sunxi_gpio.c:1.22
--- src/sys/arch/arm/sunxi/sunxi_gpio.c:1.21	Thu May 31 20:52:53 2018
+++ src/sys/arch/arm/sunxi/sunxi_gpio.c	Wed Jan 23 04:21:54 2019
@@ -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 <[email protected]>
@@ -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 @@ sunxi_pinctrl_parse_function(int phandle
 {
 	const char *function;
 
-	function = fdtbus_get_string(phandle, "function");
+	function = fdtbus_pinctrl_parse_function(phandle);
 	if (function != NULL)
 		return function;
 
@@ -592,13 +592,12 @@ sunxi_pinctrl_parse_function(int phandle
 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 @@ static int
 sunxi_pinctrl_parse_bias(int phandle)
 {
 	u_int pull;
-	int bias = -1;
+	int bias;
+
+	bias = fdtbus_pinctrl_parse_bias(phandle, NULL);
+	if (bias != -1)
+		return 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) {
+	if (of_getprop_uint32(phandle, "allwinner,pull", &pull) == 0) {
 		switch (pull) {
 		case 0:
 			bias = 0;
@@ -643,7 +640,8 @@ sunxi_pinctrl_parse_drive_strength(int p
 {
 	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)

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.45 src/sys/dev/fdt/fdtvar.h:1.46
--- src/sys/dev/fdt/fdtvar.h:1.45	Sat Jan 19 20:50:48 2019
+++ src/sys/dev/fdt/fdtvar.h	Wed Jan 23 04:21:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.45 2019/01/19 20:50:48 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.46 2019/01/23 04:21:55 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -31,6 +31,7 @@
 
 #include <sys/types.h>
 #include <sys/bus.h>
+#include <sys/gpio.h>
 #include <sys/termios.h>
 
 #include <dev/i2c/i2cvar.h>
@@ -292,6 +293,14 @@ pwm_tag_t	fdtbus_pwm_acquire_index(int, 
 void		fdtbus_pinctrl_configure(void);
 int		fdtbus_pinctrl_set_config_index(int, u_int);
 int		fdtbus_pinctrl_set_config(int, const char *);
+const char *	fdtbus_pinctrl_parse_function(int);
+const void *	fdtbus_pinctrl_parse_pins(int, int *);
+const char *	fdtbus_pinctrl_parse_groups(int, int *);
+const u_int *	fdtbus_pinctrl_parse_pinmux(int, int *);
+int		fdtbus_pinctrl_parse_bias(int, int *);
+int		fdtbus_pinctrl_parse_drive(int);
+int		fdtbus_pinctrl_parse_drive_strength(int);
+int		fdtbus_pinctrl_parse_input_output(int, 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