1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019-2020 NXP
5 * PCIe DT fixup for NXP Layerscape SoCs
6 * Author: Wasim Khan <wasim.khan@nxp.com>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/soc.h>
14 #include "pcie_layerscape_fixup_common.h"
16 void ft_pci_setup(void *blob, bd_t *bd)
18 #if defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
21 svr = SVR_SOC_VER(get_svr());
23 if (svr == SVR_LX2160A && IS_SVR_REV(get_svr(), 1, 0))
24 ft_pci_setup_ls_gen4(blob, bd);
26 #endif /* CONFIG_PCIE_LAYERSCAPE_GEN4 */
27 ft_pci_setup_ls(blob, bd);
30 #if defined(CONFIG_FSL_LAYERSCAPE)
31 int lx2_board_fix_fdt(void *fdt)
33 char *reg_name, *old_str, *new_str;
34 const char *reg_names;
35 int names_len, old_str_len, new_str_len, remaining_str_len;
40 { "csr_axi_slave", "regs" },
41 { "config_axi_slave", "config" }
45 off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
46 while (off != -FDT_ERR_NOTFOUND) {
47 fdt_setprop(fdt, off, "compatible", "fsl,ls2088a-pcie",
48 strlen("fsl,ls2088a-pcie") + 1);
50 reg_names = fdt_getprop(fdt, off, "reg-names", &names_len);
53 reg_name = (char *)reg_names;
54 remaining_str_len = names_len - (reg_name - reg_names);
56 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_str_len) {
57 old_str = reg_names_map[i].old_str;
58 new_str = reg_names_map[i].new_str;
59 old_str_len = strlen(old_str);
60 new_str_len = strlen(new_str);
61 if (memcmp(reg_name, old_str, old_str_len) == 0) {
62 /* first only leave required bytes for new_str
63 * and copy rest of the string after it
65 memcpy(reg_name + new_str_len,
66 reg_name + old_str_len,
67 remaining_str_len - old_str_len);
69 /* Now copy new_str */
70 memcpy(reg_name, new_str, new_str_len);
71 names_len -= old_str_len;
72 names_len += new_str_len;
76 reg_name = memchr(reg_name, '\0', remaining_str_len);
81 remaining_str_len = names_len - (reg_name - reg_names);
83 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
84 fdt_delprop(fdt, off, "apio-wins");
85 fdt_delprop(fdt, off, "ppio-wins");
86 off = fdt_node_offset_by_compatible(fdt, off,
92 int pcie_board_fix_fdt(void *fdt)
96 svr = SVR_SOC_VER(get_svr());
98 if (svr == SVR_LX2160A && IS_SVR_REV(get_svr(), 2, 0))
99 return lx2_board_fix_fdt(fdt);
104 #ifdef CONFIG_ARCH_LX2160A
105 /* returns the next available streamid for pcie, -errno if failed */
106 int pcie_next_streamid(int currentid, int idx)
108 if (currentid > FSL_PEX_STREAM_ID_END)
111 return currentid | ((idx + 1) << 11);
114 /* returns the next available streamid for pcie, -errno if failed */
115 int pcie_next_streamid(int currentid, int idx)
117 static int next_stream_id = FSL_PEX_STREAM_ID_START;
119 if (next_stream_id > FSL_PEX_STREAM_ID_END)
122 return next_stream_id++;
125 #endif /* CONFIG_FSL_LAYERSCAPE */