blob: 77d1573ea5a22adf81138b119b7eeb829b79d40f [file] [log] [blame]
Wasim Khan54e44ef2020-01-06 12:05:57 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019-2020 NXP
4 *
5 * PCIe DT fixup for NXP Layerscape SoCs
6 * Author: Wasim Khan <wasim.khan@nxp.com>
7 *
8 */
9
10#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Wasim Khan54e44ef2020-01-06 12:05:57 +000012#include <asm/arch/clock.h>
13#include <asm/arch/soc.h>
14#include "pcie_layerscape_fixup_common.h"
15
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090016void ft_pci_setup(void *blob, struct bd_info *bd)
Wasim Khan54e44ef2020-01-06 12:05:57 +000017{
18#if defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
19 uint svr;
20
21 svr = SVR_SOC_VER(get_svr());
22
23 if (svr == SVR_LX2160A && IS_SVR_REV(get_svr(), 1, 0))
24 ft_pci_setup_ls_gen4(blob, bd);
25 else
26#endif /* CONFIG_PCIE_LAYERSCAPE_GEN4 */
27 ft_pci_setup_ls(blob, bd);
28}
Wasim Khan9d3d2302020-01-06 12:05:59 +000029
30#if defined(CONFIG_FSL_LAYERSCAPE)
Wasim Khan70bec5c2020-01-06 12:06:00 +000031int lx2_board_fix_fdt(void *fdt)
32{
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;
36 struct str_map {
37 char *old_str;
38 char *new_str;
39 } reg_names_map[] = {
40 { "csr_axi_slave", "regs" },
41 { "config_axi_slave", "config" }
42 };
43 int off = -1, i;
Hou Zhiqiangfdb1dff2020-09-13 23:12:50 +080044 const fdt32_t *prop;
45 u32 ob_wins, ib_wins;
Wasim Khan70bec5c2020-01-06 12:06:00 +000046
47 off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
48 while (off != -FDT_ERR_NOTFOUND) {
49 fdt_setprop(fdt, off, "compatible", "fsl,ls2088a-pcie",
50 strlen("fsl,ls2088a-pcie") + 1);
51
52 reg_names = fdt_getprop(fdt, off, "reg-names", &names_len);
53 if (!reg_names)
54 continue;
55 reg_name = (char *)reg_names;
56 remaining_str_len = names_len - (reg_name - reg_names);
57 i = 0;
58 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_str_len) {
59 old_str = reg_names_map[i].old_str;
60 new_str = reg_names_map[i].new_str;
61 old_str_len = strlen(old_str);
62 new_str_len = strlen(new_str);
63 if (memcmp(reg_name, old_str, old_str_len) == 0) {
64 /* first only leave required bytes for new_str
65 * and copy rest of the string after it
66 */
67 memcpy(reg_name + new_str_len,
68 reg_name + old_str_len,
69 remaining_str_len - old_str_len);
70
71 /* Now copy new_str */
72 memcpy(reg_name, new_str, new_str_len);
73 names_len -= old_str_len;
74 names_len += new_str_len;
75 i++;
76 }
77
78 reg_name = memchr(reg_name, '\0', remaining_str_len);
79 if (!reg_name)
80 break;
81 reg_name += 1;
82
83 remaining_str_len = names_len - (reg_name - reg_names);
84 }
85 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
86 fdt_delprop(fdt, off, "apio-wins");
87 fdt_delprop(fdt, off, "ppio-wins");
88 off = fdt_node_offset_by_compatible(fdt, off,
89 "fsl,lx2160a-pcie");
90 }
Hou Zhiqiangfdb1dff2020-09-13 23:12:50 +080091
92 /* Fixup PCIe EP nodes */
93 off = -1;
94 off = fdt_node_offset_by_compatible(fdt, off, "fsl,lx2160a-pcie-ep");
95 while (off != -FDT_ERR_NOTFOUND) {
96 fdt_setprop_string(fdt, off, "compatible",
97 "fsl,lx2160ar2-pcie-ep");
98 prop = fdt_getprop(fdt, off, "apio-wins", NULL);
99 if (!prop) {
100 printf("%s: Failed to fixup PCIe EP node @0x%x\n",
101 __func__, off);
102 continue;
103 }
104
105 ob_wins = fdt32_to_cpu(*prop);
106 ib_wins = (ob_wins == 256) ? 24 : 8;
107 fdt_setprop_u32(fdt, off, "num-ib-windows", ib_wins);
108 fdt_setprop_u32(fdt, off, "num-ob-windows", ob_wins);
109 fdt_delprop(fdt, off, "apio-wins");
110
111 off = fdt_node_offset_by_compatible(fdt, off,
112 "fsl,lx2160a-pcie-ep");
113 }
114
Wasim Khan70bec5c2020-01-06 12:06:00 +0000115 return 0;
116}
117
118int pcie_board_fix_fdt(void *fdt)
119{
120 uint svr;
121
122 svr = SVR_SOC_VER(get_svr());
123
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530124 if ((svr == SVR_LX2160A || svr == SVR_LX2162A ||
125 svr == SVR_LX2120A || svr == SVR_LX2080A ||
126 svr == SVR_LX2122A || svr == SVR_LX2082A) &&
127 IS_SVR_REV(get_svr(), 2, 0))
Wasim Khan70bec5c2020-01-06 12:06:00 +0000128 return lx2_board_fix_fdt(fdt);
129
130 return 0;
131}
132
Meenakshi Aggarwalccb5d5d2020-10-29 19:16:16 +0530133#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
Wasim Khan9d3d2302020-01-06 12:05:59 +0000134/* returns the next available streamid for pcie, -errno if failed */
135int pcie_next_streamid(int currentid, int idx)
136{
137 if (currentid > FSL_PEX_STREAM_ID_END)
138 return -EINVAL;
139
140 return currentid | ((idx + 1) << 11);
141}
142#else
143/* returns the next available streamid for pcie, -errno if failed */
144int pcie_next_streamid(int currentid, int idx)
145{
146 static int next_stream_id = FSL_PEX_STREAM_ID_START;
147
148 if (next_stream_id > FSL_PEX_STREAM_ID_END)
149 return -EINVAL;
150
151 return next_stream_id++;
152}
153#endif
154#endif /* CONFIG_FSL_LAYERSCAPE */