summaryrefslogtreecommitdiff
path: root/common/fdt_decode.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2011-05-16 10:57:16 -0700
committerSimon Glass <sjg@chromium.org>2011-08-24 10:01:33 -0700
commit16016e7f644ba2301848f7769af6192cafc45c20 (patch)
tree8194afb175e3f5bcb278d8c270bc60ede11c1ad6 /common/fdt_decode.c
parent85ef9e2437c06b70478013ac6203df5daaf79a29 (diff)
fdt: Use device tree to provide SPI switch details
Rather than having the Seaboard SPI/UART switch in CONFIG options in the header files, use the device tree to configure this BUG=chromium-os:11623 TEST=build and boot U-Boot on Seaboard Change-Id: If3b92b685b5fe31a97ef4bc3578a6aa00208d827 Reviewed-on: http://gerrit.chromium.org/gerrit/1661 Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/fdt_decode.c')
-rw-r--r--common/fdt_decode.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index d316d918d8..6af6af9907 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -31,6 +31,7 @@
*/
static struct fdt_compat compat_types[] = {
{ COMPAT_UNKNOWN, "<none>" },
+ { COMPAT_SPI_UART_SWITCH, "spi-uart-select" },
};
/**
@@ -99,6 +100,28 @@ static s32 get_int(const void *blob, int node, const char *prop_name,
}
/**
+ * Look up a phandle and follow it to its node. Then return the offset
+ * of that node.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @return node offset if found, -ve error code on error
+ */
+static int lookup_phandle(const void *blob, int node, const char *prop_name)
+{
+ const u32 *phandle;
+ int lookup;
+
+ phandle = fdt_getprop(blob, node, prop_name, NULL);
+ if (!phandle)
+ return -FDT_ERR_NOTFOUND;
+
+ lookup = fdt_node_offset_by_phandle(blob, fdt32_to_cpu(*phandle));
+ return lookup;
+}
+
+/**
* Checks whether a node is enabled.
* This looks for a 'status' property. If this exists, then returns 1 if
* the status is 'ok' and 0 otherwise. If there is no status property,
@@ -164,3 +187,27 @@ enum fdt_compat_id fdt_decode_lookup(const void *blob, int node)
return id;
return COMPAT_UNKNOWN;
}
+
+int fdt_decode_get_spi_switch(const void *blob, struct fdt_spi_uart *config)
+{
+ int node, uart_node;
+ const u32 *gpio;
+
+ node = fdt_node_offset_by_compatible(blob, 0,
+ "nvidia,spi-uart-switch");
+ if (node < 0)
+ return node;
+
+ uart_node = lookup_phandle(blob, node, "uart");
+ if (uart_node < 0)
+ return uart_node;
+ config->port = get_int(blob, uart_node, "id", -1);
+ if (config->port == -1)
+ return -FDT_ERR_NOTFOUND;
+ config->gpio = -1;
+ config->regs = (NS16550_t)get_addr(blob, uart_node, "reg");
+ gpio = fdt_getprop(blob, node, "gpios", NULL);
+ if (gpio)
+ config->gpio = fdt32_to_cpu(gpio[1]);
+ return 0;
+}