blob: 4db3c76d72985bec721ec9c6c3ed8d3fd8756c1d [file] [log] [blame]
Minghuan Lian0e3a2b92015-03-20 19:28:16 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor, Inc.
Minghuan Lian0e3a2b92015-03-20 19:28:16 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/arch/fsl_serdes.h>
Minghuan Lian0e3a2b92015-03-20 19:28:16 -07009
10struct serdes_config {
11 u8 protocol;
12 u8 lanes[SRDS_MAX_LANES];
13};
14
15static struct serdes_config serdes1_cfg_tbl[] = {
16 /* SerDes 1 */
Pratiyush Srivastava39d412f2016-03-18 17:14:19 +053017 {0x03, {PCIE2, PCIE2, PCIE2, PCIE2, PCIE1, PCIE1, PCIE1, PCIE1 } },
Minghuan Lian0e3a2b92015-03-20 19:28:16 -070018 {0x05, {PCIE2, PCIE2, PCIE2, PCIE2, SGMII4, SGMII3, SGMII2, SGMII1 } },
19 {0x07, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, SGMII2,
20 SGMII1 } },
21 {0x09, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, SGMII2,
22 SGMII1 } },
23 {0x0A, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, SGMII2,
24 SGMII1 } },
25 {0x0C, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, SGMII2,
26 SGMII1 } },
27 {0x0E, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, SGMII2,
28 SGMII1 } },
29 {0x26, {SGMII8, SGMII7, SGMII6, SGMII5, SGMII4, SGMII3, XFI2, XFI1 } },
30 {0x28, {SGMII8, SGMII7, SGMII6, SGMII5, XFI4, XFI3, XFI2, XFI1 } },
31 {0x2A, {XFI8, XFI7, XFI6, XFI5, XFI4, XFI3, XFI2, XFI1 } },
32 {0x2B, {SGMII8, SGMII7, SGMII6, SGMII5, XAUI1, XAUI1, XAUI1, XAUI1 } },
33 {0x32, {XAUI2, XAUI2, XAUI2, XAUI2, XAUI1, XAUI1, XAUI1, XAUI1 } },
Pratiyush Srivastava39d412f2016-03-18 17:14:19 +053034 {0x33, {PCIE2, PCIE2, PCIE2, PCIE2, QSGMII_D, QSGMII_C, QSGMII_B,
35 QSGMII_A} },
36 {0x35, {QSGMII_D, QSGMII_C, QSGMII_B, PCIE2, XFI4, XFI3, XFI2, XFI1 } },
Priyanka Jaine2da6232016-11-03 17:50:51 +053037 {0x39, {SGMII8, SGMII7, SGMII6, PCIE2, SGMII4, SGMII3, SGMII2,
38 PCIE1 } },
Priyanka Jain594f2fd2016-11-29 16:45:05 +053039 {0x3B, {XFI8, XFI7, XFI6, PCIE2, XFI4, XFI3, XFI2, PCIE1 } },
Priyanka Jaine2da6232016-11-03 17:50:51 +053040 {0x4B, {PCIE2, PCIE2, PCIE2, PCIE2, XFI4, XFI3, XFI2, XFI1 } },
41 {0x4C, {XFI8, XFI7, XFI6, XFI5, PCIE1, PCIE1, PCIE1, PCIE1 } },
42 {0x4D, {SGMII8, SGMII7, PCIE2, PCIE2, SGMII4, SGMII3, PCIE1, PCIE1 } },
Minghuan Lian0e3a2b92015-03-20 19:28:16 -070043 {}
44};
45static struct serdes_config serdes2_cfg_tbl[] = {
46 /* SerDes 2 */
47 {0x07, {SGMII9, SGMII10, SGMII11, SGMII12, SGMII13, SGMII14, SGMII15,
48 SGMII16 } },
49 {0x09, {SGMII9, SGMII10, SGMII11, SGMII12, SGMII13, SGMII14, SGMII15,
50 SGMII16 } },
51 {0x0A, {SGMII9, SGMII10, SGMII11, SGMII12, SGMII13, SGMII14, SGMII15,
52 SGMII16 } },
53 {0x0C, {SGMII9, SGMII10, SGMII11, SGMII12, SGMII13, SGMII14, SGMII15,
54 SGMII16 } },
55 {0x0E, {SGMII9, SGMII10, SGMII11, SGMII12, SGMII13, SGMII14, SGMII15,
56 SGMII16 } },
57 {0x3D, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3 } },
58 {0x3E, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3, PCIE3 } },
59 {0x3F, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, PCIE4, PCIE4 } },
60 {0x40, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, PCIE4, PCIE4 } },
61 {0x41, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, SATA1, SATA2 } },
62 {0x42, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, SATA1, SATA2 } },
63 {0x43, {PCIE3, PCIE3, PCIE3, PCIE3, NONE, NONE, SATA1, SATA2 } },
64 {0x44, {PCIE3, PCIE3, PCIE3, PCIE3, NONE, NONE, SATA1, SATA2 } },
Pratiyush Srivastava39d412f2016-03-18 17:14:19 +053065 {0x45, {SGMII9, SGMII10, SGMII11, SGMII12, PCIE4, PCIE4, PCIE4,
Minghuan Lian0e3a2b92015-03-20 19:28:16 -070066 PCIE4 } },
Pratiyush Srivastava39d412f2016-03-18 17:14:19 +053067 {0x47, {PCIE3, SGMII10, SGMII11, SGMII12, PCIE4, SGMII14, SGMII15,
68 SGMII16 } },
Minghuan Lian0e3a2b92015-03-20 19:28:16 -070069 {0x49, {SGMII9, SGMII10, SGMII11, SGMII12, PCIE4, PCIE4, SATA1,
70 SATA2 } },
71 {0x4A, {SGMII9, SGMII10, SGMII11, SGMII12, PCIE4, PCIE4, SATA1,
72 SATA2 } },
Santan Kumarf4019022017-04-05 14:34:32 +053073 {0x51, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, PCIE4, PCIE4 } },
Priyanka Jaine2da6232016-11-03 17:50:51 +053074 {0x57, {PCIE3, PCIE3, PCIE3, PCIE3, PCIE4, PCIE4, SGMII15, SGMII16 } },
Minghuan Lian0e3a2b92015-03-20 19:28:16 -070075 {}
76};
77
78static struct serdes_config *serdes_cfg_tbl[] = {
79 serdes1_cfg_tbl,
80 serdes2_cfg_tbl,
81};
82
83enum srds_prtcl serdes_get_prtcl(int serdes, int cfg, int lane)
84{
85 struct serdes_config *ptr;
86
87 if (serdes >= ARRAY_SIZE(serdes_cfg_tbl))
88 return 0;
89
90 ptr = serdes_cfg_tbl[serdes];
91 while (ptr->protocol) {
92 if (ptr->protocol == cfg)
93 return ptr->lanes[lane];
94 ptr++;
95 }
96
97 return 0;
98}
99
100int is_serdes_prtcl_valid(int serdes, u32 prtcl)
101{
102 int i;
103 struct serdes_config *ptr;
104
105 if (serdes >= ARRAY_SIZE(serdes_cfg_tbl))
106 return 0;
107
108 ptr = serdes_cfg_tbl[serdes];
109 while (ptr->protocol) {
110 if (ptr->protocol == prtcl)
111 break;
112 ptr++;
113 }
114
115 if (!ptr->protocol)
116 return 0;
117
118 for (i = 0; i < SRDS_MAX_LANES; i++) {
119 if (ptr->lanes[i] != NONE)
120 return 1;
121 }
122
123 return 0;
124}