Merge branch '2021-10-12-assorted-fixes-and-updates'
[platform/kernel/u-boot.git] / lib / fdtdec.c
index b8fc5e2..af92e65 100644 (file)
@@ -21,6 +21,7 @@
 #include <mapmem.h>
 #include <linux/libfdt.h>
 #include <serial.h>
+#include <asm/global_data.h>
 #include <asm/sections.h>
 #include <linux/ctype.h>
 #include <linux/lzo.h>
@@ -46,8 +47,6 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
        COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"),
        COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"),
-       COMPAT(SMSC_LAN9215, "smsc,lan9215"),
-       COMPAT(SAMSUNG_EXYNOS5_SROMC, "samsung,exynos-sromc"),
        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"),
@@ -191,7 +190,6 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name)
        return fdtdec_get_addr_size(blob, node, prop_name, NULL);
 }
 
-#if CONFIG_IS_ENABLED(PCI) && defined(CONFIG_DM_PCI)
 int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
 {
        const char *list, *end;
@@ -239,7 +237,15 @@ int fdtdec_get_pci_bar32(const struct udevice *dev, struct fdt_pci_addr *addr,
                return -EINVAL;
 
        barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
+
+       /*
+        * There is a strange toolchain bug with nds32 which complains about
+        * an undefined reference here, even if fdtdec_get_pci_bar32() is never
+        * called. An #ifdef seems to be the only fix!
+        */
+#if !IS_ENABLED(CONFIG_NDS32)
        *bar = dm_pci_read_bar32(dev, barnum);
+#endif
 
        return 0;
 }
@@ -259,7 +265,6 @@ int fdtdec_get_pci_bus_range(const void *blob, int node,
 
        return 0;
 }
-#endif
 
 uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
                           uint64_t default_val)
@@ -404,7 +409,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
                        continue;
 
                /* Get the alias number */
-               number = simple_strtoul(path + name_len, NULL, 10);
+               number = dectoul(path + name_len, NULL);
                if (number < 0 || number >= maxcount) {
                        debug("%s: warning: alias '%s' is out of range\n",
                              __func__, path);
@@ -500,6 +505,17 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                slash = strrchr(prop, '/');
                if (strcmp(slash + 1, find_name))
                        continue;
+
+               /*
+                * Adding an extra check to distinguish DT nodes with
+                * same name
+                */
+               if (IS_ENABLED(CONFIG_PHANDLE_CHECK_SEQ)) {
+                       if (fdt_get_phandle(blob, offset) !=
+                           fdt_get_phandle(blob, fdt_path_offset(blob, prop)))
+                               continue;
+               }
+
                val = trailing_strtol(name);
                if (val != -1) {
                        *seqp = val;
@@ -589,7 +605,8 @@ int fdtdec_prepare_fdt(void)
 #ifdef CONFIG_SPL_BUILD
                puts("Missing DTB\n");
 #else
-               puts("No valid device tree binary found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
+               printf("No valid device tree binary found at %p\n",
+                      gd->fdt_blob);
 # ifdef DEBUG
                if (gd->fdt_blob) {
                        printf("fdt_blob=%p\n", gd->fdt_blob);
@@ -746,7 +763,7 @@ int fdtdec_parse_phandle_with_args(const void *blob, int src_node,
                        if (cells_name || cur_index == index) {
                                node = fdt_node_offset_by_phandle(blob,
                                                                  phandle);
-                               if (!node) {
+                               if (node < 0) {
                                        debug("%s: could not find phandle\n",
                                              fdt_get_name(blob, src_node,
                                                           NULL));
@@ -853,50 +870,6 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
        return cell;
 }
 
-int fdtdec_get_config_int(const void *blob, const char *prop_name,
-                         int default_val)
-{
-       int config_node;
-
-       debug("%s: %s\n", __func__, prop_name);
-       config_node = fdt_path_offset(blob, "/config");
-       if (config_node < 0)
-               return default_val;
-       return fdtdec_get_int(blob, config_node, prop_name, default_val);
-}
-
-int fdtdec_get_config_bool(const void *blob, const char *prop_name)
-{
-       int config_node;
-       const void *prop;
-
-       debug("%s: %s\n", __func__, prop_name);
-       config_node = fdt_path_offset(blob, "/config");
-       if (config_node < 0)
-               return 0;
-       prop = fdt_get_property(blob, config_node, prop_name, NULL);
-
-       return prop != NULL;
-}
-
-char *fdtdec_get_config_string(const void *blob, const char *prop_name)
-{
-       const char *nodep;
-       int nodeoffset;
-       int len;
-
-       debug("%s: %s\n", __func__, prop_name);
-       nodeoffset = fdt_path_offset(blob, "/config");
-       if (nodeoffset < 0)
-               return NULL;
-
-       nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
-       if (!nodep)
-               return NULL;
-
-       return (char *)nodep;
-}
-
 u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
 {
        u64 number = 0;
@@ -929,7 +902,11 @@ int fdt_get_resource(const void *fdt, int node, const char *property,
 
        while (ptr + na + ns <= end) {
                if (i == index) {
-                       res->start = fdtdec_get_number(ptr, na);
+                       if (CONFIG_IS_ENABLED(OF_TRANSLATE))
+                               res->start = fdt_translate_address(fdt, node, ptr);
+                       else
+                               res->start = fdtdec_get_number(ptr, na);
+
                        res->end = res->start;
                        res->end += fdtdec_get_number(&ptr[na], ns) - 1;
                        return 0;
@@ -1560,7 +1537,7 @@ int fdtdec_setup(void)
                return -1;
        }
 # elif defined(CONFIG_OF_PRIOR_STAGE)
-       gd->fdt_blob = (void *)prior_stage_fdt_address;
+       gd->fdt_blob = (void *)(uintptr_t)prior_stage_fdt_address;
 # endif
 # ifndef CONFIG_SPL_BUILD
        /* Allow the early environment to override the fdt address */