pci: layerscape: device tree fixup based on SoC and
authorWasim Khan <wasim.khan@nxp.com>
Mon, 6 Jan 2020 12:06:00 +0000 (12:06 +0000)
committerPriyanka Jain <priyanka.jain@nxp.com>
Fri, 24 Jan 2020 08:58:26 +0000 (14:28 +0530)
lx2160a rev1 requires layerscape_gen4 device tree fixup and
lx2160a rev2 requires layerscape device tree fixup.
Add device tree fixup for lx2160a based on SoC and Version.

Signed-off-by: Wasim Khan <wasim.khan@nxp.com>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
drivers/pci/pcie_layerscape_fixup.c
drivers/pci/pcie_layerscape_fixup_common.c
drivers/pci/pcie_layerscape_fixup_common.h

index 56de6d97becaaf21d8250a238c02fa42bb9e7e45..ec6acbb138d960d0b3ace2018607a429d78659c8 100644 (file)
@@ -207,6 +207,7 @@ static void fdt_fixup_pcie_ls(void *blob)
                fdt_pcie_set_iommu_map_entry_ls(blob, pcie, bdf >> 8,
                                                streamid);
        }
+       pcie_board_fix_fdt(blob);
 }
 #endif
 
index 828dfff03f46f569142a53c096b4e20448ce30b1..b010a6300cbf81964feae7596edab5363a02e184 100644 (file)
@@ -27,6 +27,79 @@ void ft_pci_setup(void *blob, bd_t *bd)
 }
 
 #if defined(CONFIG_FSL_LAYERSCAPE)
+int lx2_board_fix_fdt(void *fdt)
+{
+       char *reg_name, *old_str, *new_str;
+       const char *reg_names;
+       int names_len, old_str_len, new_str_len, remaining_str_len;
+       struct str_map {
+               char *old_str;
+               char *new_str;
+       } reg_names_map[] = {
+               { "csr_axi_slave", "regs" },
+               { "config_axi_slave", "config" }
+       };
+       int off = -1, i;
+
+       off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
+       while (off != -FDT_ERR_NOTFOUND) {
+               fdt_setprop(fdt, off, "compatible", "fsl,ls2088a-pcie",
+                           strlen("fsl,ls2088a-pcie") + 1);
+
+               reg_names = fdt_getprop(fdt, off, "reg-names", &names_len);
+               if (!reg_names)
+                       continue;
+               reg_name = (char *)reg_names;
+               remaining_str_len = names_len - (reg_name - reg_names);
+               i = 0;
+               while ((i < ARRAY_SIZE(reg_names_map)) && remaining_str_len) {
+                       old_str = reg_names_map[i].old_str;
+                       new_str = reg_names_map[i].new_str;
+                       old_str_len = strlen(old_str);
+                       new_str_len = strlen(new_str);
+                       if (memcmp(reg_name, old_str, old_str_len) == 0) {
+                               /* first only leave required bytes for new_str
+                                * and copy rest of the string after it
+                                */
+                               memcpy(reg_name + new_str_len,
+                                      reg_name + old_str_len,
+                                      remaining_str_len - old_str_len);
+
+                               /* Now copy new_str */
+                               memcpy(reg_name, new_str, new_str_len);
+                               names_len -= old_str_len;
+                               names_len += new_str_len;
+                               i++;
+                       }
+
+                       reg_name = memchr(reg_name, '\0', remaining_str_len);
+                       if (!reg_name)
+                               break;
+                       reg_name += 1;
+
+                       remaining_str_len = names_len - (reg_name - reg_names);
+               }
+               fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
+               fdt_delprop(fdt, off, "apio-wins");
+               fdt_delprop(fdt, off, "ppio-wins");
+               off = fdt_node_offset_by_compatible(fdt, off,
+                                                   "fsl,lx2160a-pcie");
+       }
+       return 0;
+}
+
+int pcie_board_fix_fdt(void *fdt)
+{
+       uint svr;
+
+       svr = SVR_SOC_VER(get_svr());
+
+       if (svr == SVR_LX2160A && IS_SVR_REV(get_svr(), 2, 0))
+               return lx2_board_fix_fdt(fdt);
+
+       return 0;
+}
+
 #ifdef CONFIG_ARCH_LX2160A
 /* returns the next available streamid for pcie, -errno if failed */
 int pcie_next_streamid(int currentid, int idx)
index ecf4f4408981d6c13f6ee3382f16e7320cf7d614..e1970a57905203466d355905bcaccd3803bd1193 100644 (file)
@@ -17,5 +17,6 @@ void ft_pci_setup_ls(void *blob, bd_t *bd);
 void ft_pci_setup_ls_gen4(void *blob, bd_t *bd);
 #endif /* CONFIG_PCIE_LAYERSCAPE_GEN4 */
 int pcie_next_streamid(int currentid, int id);
+int pcie_board_fix_fdt(void *fdt);
 
 #endif //_PCIE_LAYERSCAPE_FIXUP_COMMON_H_