]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - lib/fdtdec.c
cmd: add command for accessing the RPM via SMD protocol
[karo-tx-uboot.git] / lib / fdtdec.c
index b50d10516105cc0c1c4c8a72a25eec24207a6916..c65227a401ce1f00eb9d360e7b6bef859d572ca0 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <serial.h>
 #include <libfdt.h>
+#include <fdt_support.h>
 #include <fdtdec.h>
 #include <asm/sections.h>
 #include <linux/ctype.h>
@@ -19,6 +20,11 @@ DECLARE_GLOBAL_DATA_PTR;
  * Here are the type we know about. One day we might allow drivers to
  * register. For now we just put them here. The COMPAT macro allows us to
  * turn this into a sparse list later, and keeps the ID with the name.
+ *
+ * NOTE: This list is basically a TODO list for things that need to be
+ * converted to driver model. So don't add new things here unless there is a
+ * good reason why driver-model conversion is infeasible. Examples include
+ * things which are used before driver model is available.
  */
 #define COMPAT(id, name) name
 static const char * const compat_names[COMPAT_COUNT] = {
@@ -26,11 +32,8 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
        COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
        COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
-       COMPAT(NVIDIA_TEGRA20_PWM, "nvidia,tegra20-pwm"),
-       COMPAT(NVIDIA_TEGRA124_DC, "nvidia,tegra124-dc"),
-       COMPAT(NVIDIA_TEGRA124_SOR, "nvidia,tegra124-sor"),
        COMPAT(NVIDIA_TEGRA124_PMC, "nvidia,tegra124-pmc"),
-       COMPAT(NVIDIA_TEGRA20_DC, "nvidia,tegra20-dc"),
+       COMPAT(NVIDIA_TEGRA186_SDMMC, "nvidia,tegra186-sdhci"),
        COMPAT(NVIDIA_TEGRA210_SDMMC, "nvidia,tegra210-sdhci"),
        COMPAT(NVIDIA_TEGRA124_SDMMC, "nvidia,tegra124-sdhci"),
        COMPAT(NVIDIA_TEGRA30_SDMMC, "nvidia,tegra30-sdhci"),
@@ -42,40 +45,27 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(SAMSUNG_S3C2440_I2C, "samsung,s3c2440-i2c"),
        COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"),
        COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"),
-       COMPAT(GOOGLE_CROS_EC_KEYB, "google,cros-ec-keyb"),
        COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
        COMPAT(SAMSUNG_EXYNOS5_USB3_PHY, "samsung,exynos5250-usb3-phy"),
        COMPAT(SAMSUNG_EXYNOS_TMU, "samsung,exynos-tmu"),
-       COMPAT(SAMSUNG_EXYNOS_FIMD, "samsung,exynos-fimd"),
        COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"),
-       COMPAT(SAMSUNG_EXYNOS5_DP, "samsung,exynos5-dp"),
        COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"),
        COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"),
-       COMPAT(SAMSUNG_EXYNOS_SERIAL, "samsung,exynos4210-uart"),
        COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686"),
        COMPAT(GENERIC_SPI_FLASH, "spi-flash"),
        COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"),
        COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"),
-       COMPAT(SANDBOX_LCD_SDL, "sandbox,lcd-sdl"),
        COMPAT(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"),
        COMPAT(INTEL_MICROCODE, "intel,microcode"),
-       COMPAT(MEMORY_SPD, "memory-spd"),
-       COMPAT(INTEL_PANTHERPOINT_AHCI, "intel,pantherpoint-ahci"),
-       COMPAT(INTEL_MODEL_206AX, "intel,model-206ax"),
-       COMPAT(INTEL_GMA, "intel,gma"),
        COMPAT(AMS_AS3722, "ams,as3722"),
-       COMPAT(INTEL_ICH_SPI, "intel,ich-spi"),
        COMPAT(INTEL_QRK_MRC, "intel,quark-mrc"),
-       COMPAT(INTEL_X86_PINCTRL, "intel,x86-pinctrl"),
-       COMPAT(SOCIONEXT_XHCI, "socionext,uniphier-xhci"),
-       COMPAT(COMPAT_INTEL_PCH, "intel,bd82x6x"),
-       COMPAT(COMPAT_INTEL_IRQ_ROUTER, "intel,irq-router"),
        COMPAT(ALTERA_SOCFPGA_DWMAC, "altr,socfpga-stmmac"),
        COMPAT(ALTERA_SOCFPGA_DWMMC, "altr,socfpga-dw-mshc"),
        COMPAT(ALTERA_SOCFPGA_DWC2USB, "snps,dwc2"),
-       COMPAT(COMPAT_INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"),
-       COMPAT(COMPAT_INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"),
-       COMPAT(COMPAT_INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"),
+       COMPAT(INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"),
+       COMPAT(INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"),
+       COMPAT(INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"),
+       COMPAT(COMPAT_SUNXI_NAND, "allwinner,sun4i-a10-nand"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
@@ -87,7 +77,7 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id)
 
 fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
                const char *prop_name, int index, int na, int ns,
-               fdt_size_t *sizep)
+               fdt_size_t *sizep, bool translate)
 {
        const fdt32_t *prop, *prop_end;
        const fdt32_t *prop_addr, *prop_size, *prop_after_size;
@@ -122,20 +112,27 @@ fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
                return FDT_ADDR_T_NONE;
        }
 
-       addr = fdtdec_get_number(prop_addr, na);
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_OF_LIBFDT)
+       if (translate)
+               addr = fdt_translate_address(blob, node, prop_addr);
+       else
+#endif
+               addr = fdtdec_get_number(prop_addr, na);
 
        if (sizep) {
                *sizep = fdtdec_get_number(prop_size, ns);
-               debug("addr=%08llx, size=%llx\n", (u64)addr, (u64)*sizep);
+               debug("addr=%08llx, size=%llx\n", (unsigned long long)addr,
+                     (unsigned long long)*sizep);
        } else {
-               debug("addr=%08llx\n", (u64)addr);
+               debug("addr=%08llx\n", (unsigned long long)addr);
        }
 
        return addr;
 }
 
 fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
-               int node, const char *prop_name, int index, fdt_size_t *sizep)
+               int node, const char *prop_name, int index, fdt_size_t *sizep,
+               bool translate)
 {
        int na, ns;
 
@@ -156,11 +153,12 @@ fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
        debug("na=%d, ns=%d, ", na, ns);
 
        return fdtdec_get_addr_size_fixed(blob, node, prop_name, index, na,
-                                         ns, sizep);
+                                         ns, sizep, translate);
 }
 
 fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
-               const char *prop_name, int index, fdt_size_t *sizep)
+               const char *prop_name, int index, fdt_size_t *sizep,
+               bool translate)
 {
        int parent;
 
@@ -173,7 +171,7 @@ fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
        }
 
        return fdtdec_get_addr_size_auto_parent(blob, parent, node, prop_name,
-                                               index, sizep);
+                                               index, sizep, translate);
 }
 
 fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
@@ -183,7 +181,7 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
 
        return fdtdec_get_addr_size_fixed(blob, node, prop_name, 0,
                                          sizeof(fdt_addr_t) / sizeof(fdt32_t),
-                                         ns, sizep);
+                                         ns, sizep, false);
 }
 
 fdt_addr_t fdtdec_get_addr(const void *blob, int node,
@@ -751,8 +749,8 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                                node = fdt_node_offset_by_phandle(blob,
                                                                  phandle);
                                if (!node) {
-                                       debug("%s: could not find phandle\n",
-                                             fdt_get_name(blob, src_node,
+                                       printf("%s: could not find phandle\n",
+                                              fdt_get_name(blob, src_node,
                                                           NULL));
                                        goto err;
                                }
@@ -762,12 +760,12 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                                count = fdtdec_get_int(blob, node, cells_name,
                                                       -1);
                                if (count == -1) {
-                                       debug("%s: could not get %s for %s\n",
-                                             fdt_get_name(blob, src_node,
-                                                          NULL),
-                                             cells_name,
-                                             fdt_get_name(blob, node,
-                                                          NULL));
+                                       printf("%s: could not get %s for %s\n",
+                                              fdt_get_name(blob, src_node,
+                                                           NULL),
+                                              cells_name,
+                                              fdt_get_name(blob, node,
+                                                           NULL));
                                        goto err;
                                }
                        } else {
@@ -779,7 +777,7 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                         * remaining property data length
                         */
                        if (list + count > list_end) {
-                               debug("%s: arguments longer than property\n",
+                               printf("%s: arguments longer than property\n",
                                      fdt_get_name(blob, src_node, NULL));
                                goto err;
                        }
@@ -800,9 +798,9 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                                int i;
 
                                if (count > MAX_PHANDLE_ARGS) {
-                                       debug("%s: too many arguments %d\n",
-                                             fdt_get_name(blob, src_node,
-                                                          NULL), count);
+                                       printf("%s: too many arguments %d\n",
+                                              fdt_get_name(blob, src_node,
+                                                           NULL), count);
                                        count = MAX_PHANDLE_ARGS;
                                }
                                out_args->node = node;
@@ -833,6 +831,17 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
        return rc;
 }
 
+int fdtdec_get_child_count(const void *blob, int node)
+{
+       int subnode;
+       int num = 0;
+
+       fdt_for_each_subnode(blob, subnode, node)
+               num++;
+
+       return num;
+}
+
 int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
                u8 *array, int count)
 {
@@ -939,7 +948,7 @@ int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
        u32 reg[2];
 
        if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
-               debug("Node '%s' has bad/missing 'reg' property\n", name);
+               printf("Node '%s' has bad/missing 'reg' property\n", name);
                return -FDT_ERR_NOTFOUND;
        }
        entry->offset = reg[0];
@@ -1025,7 +1034,7 @@ int fdtdec_decode_memory_region(const void *blob, int config_node,
        if (config_node == -1) {
                config_node = fdt_path_offset(blob, "/config");
                if (config_node < 0) {
-                       debug("%s: Cannot find /config node\n", __func__);
+                       printf("%s: Cannot find /config node\n", __func__);
                        return -ENOENT;
                }
        }
@@ -1036,15 +1045,15 @@ int fdtdec_decode_memory_region(const void *blob, int config_node,
                 suffix);
        mem = fdt_getprop(blob, config_node, prop_name, NULL);
        if (!mem) {
-               debug("%s: No memory type for '%s', using /memory\n", __func__,
-                     prop_name);
+               printf("%s: No memory type for '%s', using /memory\n", __func__,
+                      prop_name);
                mem = "/memory";
        }
 
        node = fdt_path_offset(blob, mem);
        if (node < 0) {
-               debug("%s: Failed to find node '%s': %s\n", __func__, mem,
-                     fdt_strerror(node));
+               printf("%s: Failed to find node '%s': %s\n", __func__, mem,
+                      fdt_strerror(node));
                return -ENOENT;
        }
 
@@ -1053,8 +1062,8 @@ int fdtdec_decode_memory_region(const void *blob, int config_node,
         * use the first
         */
        if (fdtdec_decode_region(blob, node, "reg", &base, &size)) {
-               debug("%s: Failed to decode memory region %s\n", __func__,
-                     mem);
+               printf("%s: Failed to decode memory region %s\n", __func__,
+                      mem);
                return -EINVAL;
        }
 
@@ -1062,8 +1071,8 @@ int fdtdec_decode_memory_region(const void *blob, int config_node,
                 suffix);
        if (fdtdec_decode_region(blob, config_node, prop_name, &offset,
                                 &offset_size)) {
-               debug("%s: Failed to decode memory region '%s'\n", __func__,
-                     prop_name);
+               printf("%s: Failed to decode memory region '%s'\n", __func__,
+                      prop_name);
                return -EINVAL;
        }
 
@@ -1081,8 +1090,8 @@ static int decode_timing_property(const void *blob, int node, const char *name,
 
        prop = fdt_getprop(blob, node, name, &length);
        if (!prop) {
-               debug("%s: could not find property %s\n",
-                     fdt_get_name(blob, node, NULL), name);
+               printf("%s: could not find property %s\n",
+                      fdt_get_name(blob, node, NULL), name);
                return length;
        }
 
@@ -1162,7 +1171,7 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index,
        if (fdtdec_get_bool(blob, node, "doubleclk"))
                dt->flags |= DISPLAY_FLAGS_DOUBLECLK;
 
-       return 0;
+       return ret;
 }
 
 int fdtdec_setup(void)