]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/fdtdec.c
Merge git://git.denx.de/u-boot-tegra
[people/ms/u-boot.git] / lib / fdtdec.c
index 686b89da38549883c8cdaa5511c8a15d1921706d..107a892e79c274e0b6e2c44cf2516aef7d469a1e 100644 (file)
@@ -4,13 +4,16 @@
  */
 
 #ifndef USE_HOSTCC
+#include <boot_fit.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <serial.h>
 #include <libfdt.h>
+#include <fdt_support.h>
 #include <fdtdec.h>
 #include <asm/sections.h>
+#include <dm/of_extra.h>
 #include <linux/ctype.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -19,6 +22,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,15 +34,6 @@ 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_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"),
-       COMPAT(NVIDIA_TEGRA20_SDMMC, "nvidia,tegra20-sdhci"),
        COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"),
        COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"),
        COMPAT(SMSC_LAN9215, "smsc,lan9215"),
@@ -42,36 +41,35 @@ 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(SAMSUNG_EXYNOS_SYSMMU, "samsung,sysmmu-v3.3"),
        COMPAT(INTEL_MICROCODE, "intel,microcode"),
-       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(SOCIONEXT_XHCI, "socionext,uniphier-xhci"),
-       COMPAT(COMPAT_INTEL_PCH, "intel,bd82x6x"),
        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"),
+       COMPAT(ALTERA_SOCFPGA_CLK, "altr,clk-mgr"),
+       COMPAT(ALTERA_SOCFPGA_PINCTRL_SINGLE, "pinctrl-single"),
+       COMPAT(ALTERA_SOCFPGA_H2F_BRG, "altr,socfpga-hps2fpga-bridge"),
+       COMPAT(ALTERA_SOCFPGA_LWH2F_BRG, "altr,socfpga-lwhps2fpga-bridge"),
+       COMPAT(ALTERA_SOCFPGA_F2H_BRG, "altr,socfpga-fpga2hps-bridge"),
+       COMPAT(ALTERA_SOCFPGA_F2SDR0, "altr,socfpga-fpga2sdram0-bridge"),
+       COMPAT(ALTERA_SOCFPGA_F2SDR1, "altr,socfpga-fpga2sdram1-bridge"),
+       COMPAT(ALTERA_SOCFPGA_F2SDR2, "altr,socfpga-fpga2sdram2-bridge"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
@@ -83,7 +81,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;
@@ -118,7 +116,12 @@ 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 CONFIG_IS_ENABLED(OF_TRANSLATE)
+       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);
@@ -132,7 +135,8 @@ fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
 }
 
 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;
 
@@ -153,11 +157,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;
 
@@ -170,7 +175,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,
@@ -180,7 +185,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,
@@ -835,7 +840,7 @@ int fdtdec_get_child_count(const void *blob, int node)
        int subnode;
        int num = 0;
 
-       fdt_for_each_subnode(blob, subnode, node)
+       fdt_for_each_subnode(subnode, blob, node)
                num++;
 
        return num;
@@ -931,38 +936,6 @@ int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
        return 0;
 }
 
-/**
- * Read a flash entry from the fdt
- *
- * @param blob         FDT blob
- * @param node         Offset of node to read
- * @param name         Name of node being read
- * @param entry                Place to put offset and size of this node
- * @return 0 if ok, -ve on error
- */
-int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,
-                          struct fmap_entry *entry)
-{
-       const char *prop;
-       u32 reg[2];
-
-       if (fdtdec_get_int_array(blob, node, "reg", reg, 2)) {
-               debug("Node '%s' has bad/missing 'reg' property\n", name);
-               return -FDT_ERR_NOTFOUND;
-       }
-       entry->offset = reg[0];
-       entry->length = reg[1];
-       entry->used = fdtdec_get_int(blob, node, "used", entry->length);
-       prop = fdt_getprop(blob, node, "compress", NULL);
-       entry->compress_algo = prop && !strcmp(prop, "lzo") ?
-               FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE;
-       prop = fdt_getprop(blob, node, "hash", &entry->hash_size);
-       entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
-       entry->hash = (uint8_t *)prop;
-
-       return 0;
-}
-
 u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
 {
        u64 number = 0;
@@ -1013,7 +986,7 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
 {
        int index;
 
-       index = fdt_find_string(fdt, node, prop_names, name);
+       index = fdt_stringlist_search(fdt, node, prop_names, name);
        if (index < 0)
                return index;
 
@@ -1173,6 +1146,63 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index,
        return ret;
 }
 
+int fdtdec_setup_memory_size(void)
+{
+       int ret, mem;
+       struct fdt_resource res;
+
+       mem = fdt_path_offset(gd->fdt_blob, "/memory");
+       if (mem < 0) {
+               debug("%s: Missing /memory node\n", __func__);
+               return -EINVAL;
+       }
+
+       ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res);
+       if (ret != 0) {
+               debug("%s: Unable to decode first memory bank\n", __func__);
+               return -EINVAL;
+       }
+
+       gd->ram_size = (phys_size_t)(res.end - res.start + 1);
+       debug("%s: Initial DRAM size %llx\n", __func__,
+             (unsigned long long)gd->ram_size);
+
+       return 0;
+}
+
+#if defined(CONFIG_NR_DRAM_BANKS)
+int fdtdec_setup_memory_banksize(void)
+{
+       int bank, ret, mem;
+       struct fdt_resource res;
+
+       mem = fdt_path_offset(gd->fdt_blob, "/memory");
+       if (mem < 0) {
+               debug("%s: Missing /memory node\n", __func__);
+               return -EINVAL;
+       }
+
+       for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+               ret = fdt_get_resource(gd->fdt_blob, mem, "reg", bank, &res);
+               if (ret == -FDT_ERR_NOTFOUND)
+                       break;
+               if (ret != 0)
+                       return -EINVAL;
+
+               gd->bd->bi_dram[bank].start = (phys_addr_t)res.start;
+               gd->bd->bi_dram[bank].size =
+                       (phys_size_t)(res.end - res.start + 1);
+
+               debug("%s: DRAM Bank #%d: start = 0x%llx, size = 0x%llx\n",
+                     __func__, bank,
+                     (unsigned long long)gd->bd->bi_dram[bank].start,
+                     (unsigned long long)gd->bd->bi_dram[bank].size);
+       }
+
+       return 0;
+}
+#endif
+
 int fdtdec_setup(void)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
@@ -1186,10 +1216,22 @@ int fdtdec_setup(void)
                gd->fdt_blob = (ulong *)&_image_binary_end;
        else
                gd->fdt_blob = (ulong *)&__bss_end;
+
+#  elif defined CONFIG_FIT_EMBED
+       gd->fdt_blob = locate_dtb_in_fit(&_end);
+
+       if (gd->fdt_blob == NULL || gd->fdt_blob <= ((void *)&_end)) {
+               puts("Failed to find proper dtb in embedded FIT Image\n");
+               return -1;
+       }
+
 #  else
        /* FDT is at end of image */
        gd->fdt_blob = (ulong *)&_end;
 #  endif
+# elif defined(CONFIG_OF_BOARD)
+       /* Allow the board to override the fdt address. */
+       gd->fdt_blob = board_fdt_blob_setup();
 # elif defined(CONFIG_OF_HOSTFILE)
        if (sandbox_read_fdt_from_file()) {
                puts("Failed to read control FDT\n");
@@ -1198,7 +1240,7 @@ int fdtdec_setup(void)
 # endif
 # ifndef CONFIG_SPL_BUILD
        /* Allow the early environment to override the fdt address */
-       gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
+       gd->fdt_blob = (void *)env_get_ulong("fdtcontroladdr", 16,
                                                (uintptr_t)gd->fdt_blob);
 # endif
 #endif