dm: core: Enable optional use of fdt_translate_address()
authorStefan Roese <sr@denx.de>
Wed, 2 Sep 2015 05:41:12 +0000 (07:41 +0200)
committerLuka Perkov <luka.perkov@sartura.hr>
Wed, 21 Oct 2015 00:25:01 +0000 (02:25 +0200)
The current "simple" address translation simple_bus_translate() is not
working on some platforms (e.g. MVEBU). As here more complex "ranges"
properties are used in many nodes (multiple tuples etc). This patch
enables the optional use of the common fdt_translate_address() function
which handles this translation correctly.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
drivers/core/Kconfig
drivers/core/device.c

index 41f4e69..15681df 100644 (file)
@@ -120,4 +120,34 @@ config SPL_SIMPLE_BUS
          Supports the 'simple-bus' driver, which is used on some systems
          in SPL.
 
+config OF_TRANSLATE
+       bool "Translate addresses using fdt_translate_address"
+       depends on DM && OF_CONTROL
+       default y
+       help
+         If this option is enabled, the reg property will be translated
+         using the fdt_translate_address() function. This is necessary
+         on some platforms (e.g. MVEBU) using complex "ranges"
+         properties in many nodes. As this translation is not handled
+         correctly in the default simple_bus_translate() function.
+
+         If this option is not enabled, simple_bus_translate() will be
+         used for the address translation. This function is faster and
+         smaller in size than fdt_translate_address().
+
+config SPL_OF_TRANSLATE
+       bool "Translate addresses using fdt_translate_address"
+       depends on SPL_DM && SPL_OF_CONTROL
+       default n
+       help
+         If this option is enabled, the reg property will be translated
+         using the fdt_translate_address() function. This is necessary
+         on some platforms (e.g. MVEBU) using complex "ranges"
+         properties in many nodes. As this translation is not handled
+         correctly in the default simple_bus_translate() function.
+
+         If this option is not enabled, simple_bus_translate() will be
+         used for the address translation. This function is faster and
+         smaller in size than fdt_translate_address().
+
 endmenu
index 833a803..a3dc2ca 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <common.h>
 #include <fdtdec.h>
+#include <fdt_support.h>
 #include <malloc.h>
 #include <dm/device.h>
 #include <dm/device-internal.h>
@@ -585,6 +586,25 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
 #if CONFIG_IS_ENABLED(OF_CONTROL)
        fdt_addr_t addr;
 
+       if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
+               const fdt32_t *reg;
+
+               reg = fdt_getprop(gd->fdt_blob, dev->of_offset, "reg", NULL);
+               if (!reg)
+                       return FDT_ADDR_T_NONE;
+
+               /*
+                * Use the full-fledged translate function for complex
+                * bus setups.
+                */
+               return fdt_translate_address((void *)gd->fdt_blob,
+                                            dev->of_offset, reg);
+       }
+
+       /*
+        * Use the "simple" translate function for less complex
+        * bus setups.
+        */
        addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
                                                dev->parent->of_offset,
                                                dev->of_offset, "reg",