From 76759ec94eb3a32d71c32550b6b50965125afd92 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Thu, 30 Nov 2017 11:56:20 +0100 Subject: of: base: use root_node compatible as suggestion for a hostname on some SoCs we can use generic PLL and RAM initialization. In this cases we create board file only to provide a host name. With this patch host name will be created from device tree compatible. For example: compatible = "board_vendor,board", "chip_vendor,soc" the host name will be: "board" This function will not overwrite a host name which is already set by board or machine code. Signed-off-by: Oleksij Rempel Signed-off-by: Sascha Hauer --- drivers/of/base.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/base.c b/drivers/of/base.c index eabbf3d957..6a582177bf 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2360,3 +2360,35 @@ int of_graph_port_is_available(struct device_node *node) return available; } EXPORT_SYMBOL(of_graph_port_is_available); + +/** + * of_get_machine_compatible - get first compatible string from the root node. + * + * Returns the string or NULL. + */ +const char *of_get_machine_compatible(void) +{ + struct property *prop; + const char *name, *p; + + if (!root_node) + return NULL; + + prop = of_find_property(root_node, "compatible", NULL); + name = of_prop_next_string(prop, NULL); + + p = strchr(name, ','); + return p ? p + 1 : name; +} +EXPORT_SYMBOL(of_get_machine_compatible); + +static int of_init_hostname(void) +{ + const char *name; + + name = of_get_machine_compatible(); + barebox_set_hostname_no_overwrite(name ?: "barebox"); + + return 0; +} +late_initcall(of_init_hostname); -- cgit v1.2.3