diff options
-rw-r--r-- | common/fdt_decode.c | 23 | ||||
-rw-r--r-- | include/fdt_decode.h | 25 |
2 files changed, 47 insertions, 1 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c index d149bf2145b..d316d918d86 100644 --- a/common/fdt_decode.c +++ b/common/fdt_decode.c @@ -25,6 +25,14 @@ #include <fdt_support.h> #include <fdt_decode.h> +/* + * Here are the type we know about. One day we might allow drivers to + * register. For now we just put them here. + */ +static struct fdt_compat compat_types[] = { + { COMPAT_UNKNOWN, "<none>" }, +}; + /** * Look in the FDT for an alias with the given name and return its node. * @@ -122,7 +130,7 @@ void fdt_decode_uart_calc_divisor(struct fdt_uart *uart) int fdt_decode_uart_console(const void *blob, struct fdt_uart *uart, int default_baudrate) { - int node, i; + int node; node = find_alias_node(blob, "console"); if (node < 0) @@ -137,9 +145,22 @@ int fdt_decode_uart_console(const void *blob, struct fdt_uart *uart, uart->enabled = get_is_enabled(blob, node, 1); uart->interrupt = get_int(blob, node, "interrupts", -1); uart->silent = get_int(blob, node, "silent", 0); + uart->compat = fdt_decode_lookup(blob, node); /* Calculate divisor if required */ if (uart->divisor == -1) fdt_decode_uart_calc_divisor(uart); return 0; } + +enum fdt_compat_id fdt_decode_lookup(const void *blob, int node) +{ + enum fdt_compat_id id; + + /* Search our drivers */ + for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++) + if (0 == fdt_node_check_compatible(blob, node, + compat_types[id].name)) + return id; + return COMPAT_UNKNOWN; +} diff --git a/include/fdt_decode.h b/include/fdt_decode.h index b93bf3ad62b..303d5a8d332 100644 --- a/include/fdt_decode.h +++ b/include/fdt_decode.h @@ -39,6 +39,23 @@ typedef u32 addr_t; #define addr_to_cpu(reg) be32_to_cpu(reg) #endif +/** + * Compat types that we know about and for which we might have drivers. + * Each is named COMPAT_<dir>_<filename> where <dir> is the directory + * within drivers. + */ +enum fdt_compat_id { + COMPAT_UNKNOWN, + + COMPAT_COUNT, +}; + +/** compat items that we know about and might have drivers for */ +struct fdt_compat { + enum fdt_compat_id id; + const char *name; +}; + /* Information obtained about a UART from the FDT */ struct fdt_uart { addr_t reg; /* address of registers in physical memory */ @@ -51,6 +68,7 @@ struct fdt_uart { int enabled; /* 1 to enable, 0 to disable */ int interrupt; /* interrupt line */ int silent; /* 1 for silent UART (supresses output by default) */ + enum fdt_compat_id compat; /* our selected driver */ }; /** @@ -90,3 +108,10 @@ int fdt_decode_uart_console(const void *blob, struct fdt_uart *uart, * @param uart uart structure to examine and update */ void fdt_decode_uart_calc_divisor(struct fdt_uart *uart); + +/** + * Find the compat id for a node. This looks at the 'compat' property of + * the node and looks up the corresponding ftp_compat_id. This is used for + * determining which driver will implement the decide described by the node. + */ +enum fdt_compat_id fdt_decode_lookup(const void *blob, int node); |