From 16016e7f644ba2301848f7769af6192cafc45c20 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 16 May 2011 10:57:16 -0700 Subject: 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 Tested-by: Simon Glass --- common/fdt_decode.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'common/fdt_decode.c') 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, "" }, + { COMPAT_SPI_UART_SWITCH, "spi-uart-select" }, }; /** @@ -98,6 +99,28 @@ static s32 get_int(const void *blob, int node, const char *prop_name, return default_val; } +/** + * 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 @@ -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; +} -- cgit v1.2.3