blob: c96ad0b486ebca24a8f56b693bedf1cec9483d0d [file] [log] [blame]
York Sunbcf7b3d2012-10-08 07:44:20 +00001/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
York Sunbcf7b3d2012-10-08 07:44:20 +00005 */
6
7#include <common.h>
8#include <asm/fsl_serdes.h>
9#include <asm/processor.h>
10#include <asm/io.h>
11#include "fsl_corenet2_serdes.h"
12
13struct serdes_config {
14 u8 protocol;
15 u8 lanes[SRDS_MAX_LANES];
16};
17
Poonam Aggrwal248865e2012-12-23 19:24:16 +000018#ifdef CONFIG_PPC_B4860
York Sunbcf7b3d2012-10-08 07:44:20 +000019static struct serdes_config serdes1_cfg_tbl[] = {
20 /* SerDes 1 */
Shaveta Leekha8d2ba982014-02-26 16:06:30 +053021 {0x02, {AURORA, AURORA, CPRI6, CPRI5,
22 CPRI4, CPRI3, CPRI2, CPRI1} },
23 {0x04, {AURORA, AURORA, CPRI6, CPRI5,
24 CPRI4, CPRI3, CPRI2, CPRI1} },
25 {0x05, {AURORA, AURORA, CPRI6, CPRI5,
26 CPRI4, CPRI3, CPRI2, CPRI1} },
27 {0x06, {AURORA, AURORA, CPRI6, CPRI5,
28 CPRI4, CPRI3, CPRI2, CPRI1} },
29 {0x08, {AURORA, AURORA, CPRI6, CPRI5,
30 CPRI4, CPRI3, CPRI2, CPRI1} },
31 {0x09, {AURORA, AURORA, CPRI6, CPRI5,
32 CPRI4, CPRI3, CPRI2, CPRI1} },
33 {0x0A, {AURORA, AURORA, CPRI6, CPRI5,
34 CPRI4, CPRI3, CPRI2, CPRI1} },
35 {0x0B, {AURORA, AURORA, CPRI6, CPRI5,
36 CPRI4, CPRI3, CPRI2, CPRI1} },
37 {0x0C, {AURORA, AURORA, CPRI6, CPRI5,
38 CPRI4, CPRI3, CPRI2, CPRI1} },
York Sunbcf7b3d2012-10-08 07:44:20 +000039 {0x0D, {CPRI8, CPRI7, CPRI6, CPRI5,
40 CPRI4, CPRI3, CPRI2, CPRI1}},
41 {0x0E, {CPRI8, CPRI7, CPRI6, CPRI5,
42 CPRI4, CPRI3, CPRI2, CPRI1}},
43 {0x12, {CPRI8, CPRI7, CPRI6, CPRI5,
44 CPRI4, CPRI3, CPRI2, CPRI1}},
45 {0x2a, {SGMII_FM1_DTSEC5, SGMII_FM1_DTSEC6,
46 CPRI6, CPRI5, CPRI4, CPRI3, CPRI2, CPRI1}},
Poonam Aggrwal1c859552012-12-23 19:22:33 +000047 {0x2C, {SGMII_FM1_DTSEC5, SGMII_FM1_DTSEC6,
48 CPRI6, CPRI5, CPRI4, CPRI3, CPRI2, CPRI1}},
49 {0x2D, {SGMII_FM1_DTSEC5, SGMII_FM1_DTSEC6,
50 CPRI6, CPRI5, CPRI4, CPRI3, CPRI2, CPRI1}},
51 {0x2E, {SGMII_FM1_DTSEC5, SGMII_FM1_DTSEC6,
52 CPRI6, CPRI5, CPRI4, CPRI3, CPRI2, CPRI1}},
York Sunbcf7b3d2012-10-08 07:44:20 +000053 {0x30, {AURORA, AURORA,
54 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
55 CPRI4, CPRI3, CPRI2, CPRI1}},
56 {0x32, {AURORA, AURORA,
57 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
58 CPRI4, CPRI3, CPRI2, CPRI1}},
59 {0x33, {AURORA, AURORA,
60 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
61 CPRI4, CPRI3, CPRI2, CPRI1}},
62 {0x34, {AURORA, AURORA,
63 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
64 CPRI4, CPRI3, CPRI2, CPRI1}},
Shaveta Leekha8d2ba982014-02-26 16:06:30 +053065 {0x39, {AURORA, AURORA, CPRI6, CPRI5,
66 CPRI4, CPRI3, CPRI2, CPRI1} },
67 {0x3A, {AURORA, AURORA, CPRI6, CPRI5,
68 CPRI4, CPRI3, CPRI2, CPRI1} },
69 {0x3C, {AURORA, AURORA, CPRI6, CPRI5,
70 CPRI4, CPRI3, CPRI2, CPRI1} },
71 {0x3D, {AURORA, AURORA, CPRI6, CPRI5,
72 CPRI4, CPRI3, CPRI2, CPRI1} },
York Sunbcf7b3d2012-10-08 07:44:20 +000073 {0x3E, {CPRI8, CPRI7, CPRI6, CPRI5,
74 CPRI4, CPRI3, CPRI2, CPRI1}},
Shaveta Leekha8d2ba982014-02-26 16:06:30 +053075 {0x5C, {AURORA, AURORA,
76 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
77 CPRI4, CPRI3, CPRI2, CPRI1} },
78 {0x5D, {AURORA, AURORA,
79 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
80 CPRI4, CPRI3, CPRI2, CPRI1} },
York Sunbcf7b3d2012-10-08 07:44:20 +000081 {}
82};
83static struct serdes_config serdes2_cfg_tbl[] = {
84 /* SerDes 2 */
85 {0x18, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
86 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
87 AURORA, AURORA, SRIO1, SRIO1}},
88 {0x1D, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
89 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
90 AURORA, AURORA, SRIO1, SRIO1}},
91 {0x2B, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
92 SRIO2, SRIO2,
93 AURORA, AURORA, SRIO1, SRIO1}},
94 {0x30, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
95 SRIO2, SRIO2,
96 AURORA, AURORA,
97 SRIO1, SRIO1}},
98 {0x49, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
99 SGMII_FM1_DTSEC3, AURORA,
100 SRIO1, SRIO1, SRIO1, SRIO1}},
101 {0x4A, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
102 SGMII_FM1_DTSEC3, AURORA,
103 SRIO1, SRIO1, SRIO1, SRIO1}},
104 {0x4C, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
105 SGMII_FM1_DTSEC3, AURORA,
106 SRIO1, SRIO1, SRIO1, SRIO1}},
107 {0x4E, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
108 SGMII_FM1_DTSEC3, AURORA,
109 SRIO1, SRIO1, SRIO1, SRIO1}},
Poonam Aggrwal1c859552012-12-23 19:22:33 +0000110 {0x7A, {SRIO2, SRIO2, SRIO2, SRIO2,
111 SRIO1, SRIO1, SRIO1, SRIO1}},
York Sunbcf7b3d2012-10-08 07:44:20 +0000112 {0x84, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
113 SRIO2, SRIO2, AURORA, AURORA,
114 XFI_FM1_MAC9, XFI_FM1_MAC10}},
115 {0x85, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
116 SRIO2, SRIO2, AURORA, AURORA,
117 XFI_FM1_MAC9, XFI_FM1_MAC10}},
118 {0x87, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
119 SRIO2, SRIO2,
120 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
121 XFI_FM1_MAC9, XFI_FM1_MAC10}},
Poonam Aggrwal1c859552012-12-23 19:22:33 +0000122 {0x8D, {SRIO2, SRIO2, SRIO2, SRIO2,
123 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
124 XFI_FM1_MAC9, XFI_FM1_MAC10}},
York Sunbcf7b3d2012-10-08 07:44:20 +0000125 {0x93, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
126 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
127 XAUI_FM1_MAC10, XAUI_FM1_MAC10,
128 XAUI_FM1_MAC10, XAUI_FM1_MAC10}},
129 {0x9E, {PCIE1, PCIE1, PCIE1, PCIE1,
130 XAUI_FM1_MAC10, XAUI_FM1_MAC10,
131 XAUI_FM1_MAC10, XAUI_FM1_MAC10}},
132 {0x9A, {PCIE1, PCIE1,
133 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
134 XAUI_FM1_MAC10, XAUI_FM1_MAC10,
135 XAUI_FM1_MAC10, XAUI_FM1_MAC10}},
136 {0xB2, {PCIE1, PCIE1, PCIE1, PCIE1,
137 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
138 XFI_FM1_MAC9, XFI_FM1_MAC10}},
139 {0xC3, {XAUI_FM1_MAC9, XAUI_FM1_MAC9,
140 XAUI_FM1_MAC9, XAUI_FM1_MAC9,
141 SRIO1, SRIO1, SRIO1, SRIO1}},
Poonam Aggrwal1c859552012-12-23 19:22:33 +0000142 {0x98, {XAUI_FM1_MAC9, XAUI_FM1_MAC9,
143 XAUI_FM1_MAC9, XAUI_FM1_MAC9,
144 XAUI_FM1_MAC10, XAUI_FM1_MAC10,
145 XAUI_FM1_MAC10, XAUI_FM1_MAC10}},
York Sunbcf7b3d2012-10-08 07:44:20 +0000146 {}
147};
Poonam Aggrwal248865e2012-12-23 19:24:16 +0000148#endif
149
150#ifdef CONFIG_PPC_B4420
151static struct serdes_config serdes1_cfg_tbl[] = {
152 {0x0D, {NONE, NONE, CPRI6, CPRI5,
153 CPRI4, CPRI3, NONE, NONE} },
154 {0x0E, {NONE, NONE, CPRI8, CPRI5,
155 CPRI4, CPRI3, NONE, NONE} },
156 {0x0F, {NONE, NONE, CPRI6, CPRI5,
157 CPRI4, CPRI3, NONE, NONE} },
158 {0x18, {NONE, NONE,
159 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
160 NONE, NONE, NONE, NONE} },
161 {0x1B, {NONE, NONE,
162 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
163 NONE, NONE, NONE, NONE} },
164 {0x1E, {NONE, NONE, AURORA, AURORA,
165 NONE, NONE, NONE, NONE} },
166 {0x21, {NONE, NONE, AURORA, AURORA,
167 NONE, NONE, NONE, NONE} },
168 {0x3E, {NONE, NONE, CPRI6, CPRI5,
169 CPRI4, CPRI3, NONE, NONE} },
170 {}
171};
172static struct serdes_config serdes2_cfg_tbl[] = {
173 {0x49, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
174 SGMII_FM1_DTSEC3, AURORA,
175 NONE, NONE, NONE, NONE} },
176 {0x4A, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
177 SGMII_FM1_DTSEC3, AURORA,
178 NONE, NONE, NONE, NONE} },
179 {0x6F, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
180 AURORA, AURORA, NONE, NONE, NONE, NONE} },
181 {0x70, {SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2,
182 AURORA, AURORA, NONE, NONE, NONE, NONE} },
183 {0x9A, {PCIE1, PCIE1,
184 SGMII_FM1_DTSEC3, SGMII_FM1_DTSEC4,
185 NONE, NONE, NONE, NONE} },
186 {0x9E, {PCIE1, PCIE1, PCIE1, PCIE1,
187 NONE, NONE, NONE, NONE} },
188 {}
189};
190#endif
191
York Sunbcf7b3d2012-10-08 07:44:20 +0000192static struct serdes_config *serdes_cfg_tbl[] = {
193 serdes1_cfg_tbl,
194 serdes2_cfg_tbl,
195};
196
197enum srds_prtcl serdes_get_prtcl(int serdes, int cfg, int lane)
198{
199 struct serdes_config *ptr;
200
201 if (serdes >= ARRAY_SIZE(serdes_cfg_tbl))
202 return 0;
203
204 ptr = serdes_cfg_tbl[serdes];
205 while (ptr->protocol) {
206 if (ptr->protocol == cfg)
207 return ptr->lanes[lane];
208 ptr++;
209 }
210
211 return 0;
212}
213
214int is_serdes_prtcl_valid(int serdes, u32 prtcl)
215{
216 int i;
217 struct serdes_config *ptr;
218
219 if (serdes >= ARRAY_SIZE(serdes_cfg_tbl))
220 return 0;
221
222 ptr = serdes_cfg_tbl[serdes];
223 while (ptr->protocol) {
224 if (ptr->protocol == prtcl)
225 break;
226 ptr++;
227 }
228
229 if (!ptr->protocol)
230 return 0;
231
232 for (i = 0; i < SRDS_MAX_LANES; i++) {
233 if (ptr->lanes[i] != NONE)
234 return 1;
235 }
236
237 return 0;
238}