of: Add of_flat_dt_get_machine_name to device tree library
authorChristoffer Dall <christoffer.dall@linaro.org>
Wed, 29 Oct 2014 14:57:37 +0000 (15:57 +0100)
committerChristoffer Dall <christoffer.dall@linaro.org>
Sat, 13 Dec 2014 15:13:46 +0000 (16:13 +0100)
Add a function to retreive the machine name from the device tree once
the device tree has been unflattened.  This is particularly useful for
multi-flavored virtual machine boards (like the Xen, virt, and ranchu
boards) where it is useful for user space to know which flavor of a
device-tree driven board you are running.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
drivers/of/fdt.c
include/linux/of_fdt.h

index 5da7421aace581f1ee3e8817124965ed4d866069..7e0352bed777a7583d1d8ea4152301b71f7a5389 100644 (file)
@@ -684,6 +684,18 @@ static const char *config_cmdline = CONFIG_CMDLINE;
 static const char *config_cmdline = "";
 #endif
 
+
+const char * __init of_flat_dt_get_machine_name(void)
+{
+       const char *name;
+       unsigned long dt_root = of_get_flat_dt_root();
+
+       name = of_get_flat_dt_prop(dt_root, "model", NULL);
+       if (!name)
+               name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
+       return name;
+}
+
 int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
                                     int depth, void *data)
 {
index 61f75f6be5ba86779e76a7d6786592825d463087..c4d5ca5161200c305ea49349d8d8ff53c29bd6b6 100644 (file)
@@ -135,9 +135,11 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
                                   int depth, void *data);
 
 /* Other Prototypes */
+extern const char *of_flat_dt_get_machine_name(void);
 extern void unflatten_device_tree(void);
 extern void early_init_devtree(void *);
 #else /* CONFIG_OF_FLATTREE */
+extern const char *of_flat_dt_get_machine_name(void) { return NULL; }
 static inline void unflatten_device_tree(void) {}
 #endif /* CONFIG_OF_FLATTREE */