summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2019-10-01 23:32:52 +0000
committerjmcneill <jmcneill@NetBSD.org>2019-10-01 23:32:52 +0000
commita4dd1f1a55dfd0b8a189e1315993b287d7d614c1 (patch)
tree7ec776248a7ba6eebabfc29b885053149ffeb4a8 /sys/dev
parent3702d64516f43d9bb90af701fcffe60589f00613 (diff)
Add support for devices with separate "init" and "default" pinctrl states.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/fdt/fdt_pinctrl.c39
-rw-r--r--sys/dev/fdt/fdtbus.c48
-rw-r--r--sys/dev/fdt/fdtvar.h4
-rw-r--r--sys/dev/i2c/axppmic.c7
4 files changed, 57 insertions, 41 deletions
diff --git a/sys/dev/fdt/fdt_pinctrl.c b/sys/dev/fdt/fdt_pinctrl.c
index 4c996fc4cc1..e6a7aef2f0f 100644
--- a/sys/dev/fdt/fdt_pinctrl.c
+++ b/sys/dev/fdt/fdt_pinctrl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_pinctrl.c,v 1.9 2019/09/27 20:05:53 jmcneill Exp $ */
+/* $NetBSD: fdt_pinctrl.c,v 1.10 2019/10/01 23:32:52 jmcneill Exp $ */
/*-
* Copyright (c) 2019 Jason R. Thorpe
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.9 2019/09/27 20:05:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_pinctrl.c,v 1.10 2019/10/01 23:32:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -123,42 +123,17 @@ fdtbus_pinctrl_set_config(int phandle, const char *cfgname)
err = fdtbus_get_index(phandle, "pinctrl-names", cfgname, &index);
if (err != 0)
- return -1;
+ return ENOENT;
return fdtbus_pinctrl_set_config_index(phandle, index);
}
-static void
-fdtbus_pinctrl_configure_node(int phandle)
+bool
+fdtbus_pinctrl_has_config(int phandle, const char *cfgname)
{
- char buf[256];
- int child, error;
-
- for (child = OF_child(phandle); child; child = OF_peer(child)) {
- if (!fdtbus_status_okay(child))
- continue;
-
- /* Configure child nodes */
- fdtbus_pinctrl_configure_node(child);
-
- /*
- * Set default configuration for this node. This may fail if the
- * pinctrl provider is missing; that's OK, we will re-configure
- * when that provider attaches.
- */
- fdtbus_get_path(child, buf, sizeof(buf));
- error = fdtbus_pinctrl_set_config(child, "default");
- if (error == 0)
- aprint_debug("pinctrl: set default config for %s\n", buf);
- else if (error != ENOENT)
- aprint_debug("pinctrl: failed to set default config for %s: %d\n", buf, error);
- }
-}
+ u_int index;
-void
-fdtbus_pinctrl_configure(void)
-{
- fdtbus_pinctrl_configure_node(OF_finddevice("/"));
+ return fdtbus_get_index(phandle, "pinctrl-names", cfgname, &index) == 0;
}
/*
diff --git a/sys/dev/fdt/fdtbus.c b/sys/dev/fdt/fdtbus.c
index f013646cd0f..5b6b9adecf8 100644
--- a/sys/dev/fdt/fdtbus.c
+++ b/sys/dev/fdt/fdtbus.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.29 2019/05/25 19:21:34 jmcneill Exp $ */
+/* $NetBSD: fdtbus.c,v 1.30 2019/10/01 23:32:52 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.29 2019/05/25 19:21:34 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.30 2019/10/01 23:32:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -56,6 +56,8 @@ struct fdt_node {
u_int n_order;
+ bool n_pinctrl_init;
+
TAILQ_ENTRY(fdt_node) n_nodes;
};
@@ -79,6 +81,8 @@ static cfdata_t fdt_scan_best(struct fdt_softc *, struct fdt_node *);
static void fdt_scan(struct fdt_softc *, int);
static void fdt_add_node(struct fdt_node *);
static u_int fdt_get_order(int);
+static void fdt_pre_attach(struct fdt_node *);
+static void fdt_post_attach(struct fdt_node *);
static const char * const fdtbus_compatible[] =
{ "simple-bus", NULL };
@@ -313,14 +317,20 @@ fdt_scan(struct fdt_softc *sc, int pass)
/*
* Attach the device.
*/
+ fdt_pre_attach(node);
node->n_dev = config_attach_loc(node->n_bus, cf_pass, locs,
&faa, fdtbus_print);
+ if (node->n_dev != NULL)
+ fdt_post_attach(node);
} else {
/*
* Default pass.
*/
+ fdt_pre_attach(node);
node->n_dev = config_found_sm_loc(node->n_bus, "fdt", locs,
&faa, fdtbus_print, fdt_scan_submatch);
+ if (node->n_dev != NULL)
+ fdt_post_attach(node);
}
if (node->n_dev) {
@@ -332,6 +342,40 @@ fdt_scan(struct fdt_softc *sc, int pass)
}
static void
+fdt_pre_attach(struct fdt_node *node)
+{
+ const char *cfgname;
+ int error;
+
+ node->n_pinctrl_init = fdtbus_pinctrl_has_config(node->n_phandle, "init");
+
+ cfgname = node->n_pinctrl_init ? "init" : "default";
+
+ aprint_debug_dev(node->n_bus, "set %s config for %s\n", cfgname, node->n_name);
+
+ error = fdtbus_pinctrl_set_config(node->n_phandle, cfgname);
+ if (error != 0 && error != ENOENT)
+ aprint_debug_dev(node->n_bus,
+ "failed to set %s config on %s: %d\n",
+ cfgname, node->n_name, error);
+}
+
+static void
+fdt_post_attach(struct fdt_node *node)
+{
+ int error;
+
+ if (node->n_pinctrl_init) {
+ aprint_debug_dev(node->n_bus, "set default config for %s\n", node->n_name);
+ error = fdtbus_pinctrl_set_config(node->n_phandle, "default");
+ if (error != 0 && error != ENOENT)
+ aprint_debug_dev(node->n_bus,
+ "failed to set default config on %s: %d\n",
+ node->n_name, error);
+ }
+}
+
+static void
fdt_add_node(struct fdt_node *new_node)
{
struct fdt_node *node;
diff --git a/sys/dev/fdt/fdtvar.h b/sys/dev/fdt/fdtvar.h
index 94eef309d26..13545e4063a 100644
--- a/sys/dev/fdt/fdtvar.h
+++ b/sys/dev/fdt/fdtvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.53 2019/08/13 16:46:49 tnn Exp $ */
+/* $NetBSD: fdtvar.h,v 1.54 2019/10/01 23:32:52 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -315,9 +315,9 @@ audio_dai_tag_t fdtbus_dai_acquire(int, const char *);
audio_dai_tag_t fdtbus_dai_acquire_index(int, const char *, int);
pwm_tag_t fdtbus_pwm_acquire(int, const char *);
pwm_tag_t fdtbus_pwm_acquire_index(int, const char *, int);
-void fdtbus_pinctrl_configure(void);
int fdtbus_pinctrl_set_config_index(int, u_int);
int fdtbus_pinctrl_set_config(int, const char *);
+bool fdtbus_pinctrl_has_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 *);
diff --git a/sys/dev/i2c/axppmic.c b/sys/dev/i2c/axppmic.c
index 0a1bb64bcb7..4309b184b7c 100644
--- a/sys/dev/i2c/axppmic.c
+++ b/sys/dev/i2c/axppmic.c
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.25 2019/07/27 16:02:27 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.26 2019/10/01 23:32:52 jmcneill Exp $ */
/*-
* Copyright (c) 2014-2018 Jared McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.25 2019/07/27 16:02:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.26 2019/10/01 23:32:52 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -992,9 +992,6 @@ axppmic_attach(device_t parent, device_t self, void *aux)
}
}
- /* Notify pinctrl drivers that regulators are available. */
- fdtbus_pinctrl_configure();
-
if (c->has_battery)
axppmic_attach_sensors(sc);
}