summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2020-02-10 10:35:17 +0100
committerChristian Mauderer <christian.mauderer@embedded-brains.de>2020-02-11 09:17:02 +0100
commitadf7e7538f3815db5ee5944daee82bb7053baf90 (patch)
tree1b8da6cc1ca3ddf7e38278d81d1e6728280dfc67
parentb58f994492261a18444e45b4dadc3989d0b20d98 (diff)
bsp/imx: Parse fdt pinctrl values and setup iomux
Update #3869.
-rw-r--r--bsps/arm/imx/start/imx_iomux.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/bsps/arm/imx/start/imx_iomux.c b/bsps/arm/imx/start/imx_iomux.c
index f6235d3cf4..d97e35deef 100644
--- a/bsps/arm/imx/start/imx_iomux.c
+++ b/bsps/arm/imx/start/imx_iomux.c
@@ -109,6 +109,47 @@ static struct iomux_softc iomux_sc_instance;
#define iomux_sc (&iomux_sc_instance);
+/* Return true if there is no status or status is "okay" or "ok". */
+static bool
+imx_fdt_node_status_okay(const void *fdt, int node)
+{
+ const void *status;
+ int len;
+
+ status = fdt_getprop(fdt, node, "status", &len);
+ if ((status == NULL) ||
+ (strncmp(status, "okay", MIN(5, len)) == 0) ||
+ (strncmp(status, "ok", MIN(3, len)) == 0)) {
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * Walk through all subnodes and handle "pinctrl-0" if the node is enabled. This
+ * does roughly the same as FreeBSDs fdt_pinctrl_configure_tree but without the
+ * whole open firmware (OF*) functions.
+ */
+static void
+imx_pinctrl_configure_children(const void *fdt, int parent)
+{
+ int node;
+ const uint32_t *phandle;
+ int len;
+
+ fdt_for_each_subnode(node, fdt, parent) {
+ if (imx_fdt_node_status_okay(fdt, node)) {
+ imx_pinctrl_configure_children(fdt, node);
+ phandle = fdt_getprop(fdt, node, "pinctrl-0", &len);
+ if (phandle != NULL && len == sizeof(*phandle)) {
+ imx_iomux_configure_pins(fdt,
+ fdt32_to_cpu(*phandle));
+ }
+ }
+ }
+}
+
static void
imx_iomux_init(void)
{
@@ -124,6 +165,9 @@ imx_iomux_init(void)
}
sc = iomux_sc;
sc->regs = imx_get_reg_of_node(fdt, node);
+
+ node = fdt_path_offset(fdt, "/");
+ imx_pinctrl_configure_children(fdt, node);
}
RTEMS_SYSINIT_ITEM(imx_iomux_init, RTEMS_SYSINIT_BSP_START,