2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/errno.h>
10 #include <asm/arch/fsl_serdes.h>
11 #include <asm/arch/soc.h>
13 #ifdef CONFIG_SYS_FSL_SRDS_1
14 static u8 serdes1_prtcl_map
[SERDES_PRCTL_COUNT
];
16 #ifdef CONFIG_SYS_FSL_SRDS_2
17 static u8 serdes2_prtcl_map
[SERDES_PRCTL_COUNT
];
20 int is_serdes_configured(enum srds_prtcl device
)
24 #ifdef CONFIG_SYS_FSL_SRDS_1
25 if (!serdes1_prtcl_map
[NONE
])
28 ret
|= serdes1_prtcl_map
[device
];
30 #ifdef CONFIG_SYS_FSL_SRDS_2
31 if (!serdes2_prtcl_map
[NONE
])
34 ret
|= serdes2_prtcl_map
[device
];
40 int serdes_get_first_lane(u32 sd
, enum srds_prtcl device
)
42 struct ccsr_gur __iomem
*gur
= (void *)(CONFIG_SYS_FSL_GUTS_ADDR
);
43 u32 cfg
= gur_in32(&gur
->rcwsr
[4]);
47 #ifdef CONFIG_SYS_FSL_SRDS_1
49 cfg
&= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK
;
50 cfg
>>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT
;
53 #ifdef CONFIG_SYS_FSL_SRDS_2
55 cfg
&= FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_MASK
;
56 cfg
>>= FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_SHIFT
;
60 printf("invalid SerDes%d\n", sd
);
64 /* Is serdes enabled at all? */
65 if (unlikely(cfg
== 0))
68 for (i
= 0; i
< SRDS_MAX_LANES
; i
++) {
69 if (serdes_get_prtcl(sd
, cfg
, i
) == device
)
76 int get_serdes_protocol(void)
78 struct ccsr_gur __iomem
*gur
= (void *)(CONFIG_SYS_FSL_GUTS_ADDR
);
79 u32 cfg
= gur_in32(&gur
->rcwsr
[4]) &
80 FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK
;
81 cfg
>>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT
;
86 const char *serdes_clock_to_string(u32 clock
)
89 case SRDS_PLLCR0_RFCK_SEL_100
:
91 case SRDS_PLLCR0_RFCK_SEL_125
:
93 case SRDS_PLLCR0_RFCK_SEL_156_25
:
100 void serdes_init(u32 sd
, u32 sd_addr
, u32 sd_prctl_mask
, u32 sd_prctl_shift
,
101 u8 serdes_prtcl_map
[SERDES_PRCTL_COUNT
])
103 struct ccsr_gur __iomem
*gur
= (void *)(CONFIG_SYS_FSL_GUTS_ADDR
);
107 if (serdes_prtcl_map
[NONE
])
110 memset(serdes_prtcl_map
, 0, sizeof(u8
) * SERDES_PRCTL_COUNT
);
112 cfg
= gur_in32(&gur
->rcwsr
[4]) & sd_prctl_mask
;
113 cfg
>>= sd_prctl_shift
;
114 printf("Using SERDES%d Protocol: %d (0x%x)\n", sd
+ 1, cfg
, cfg
);
116 if (!is_serdes_prtcl_valid(sd
, cfg
))
117 printf("SERDES%d[PRTCL] = 0x%x is not valid\n", sd
+ 1, cfg
);
119 for (lane
= 0; lane
< SRDS_MAX_LANES
; lane
++) {
120 enum srds_prtcl lane_prtcl
= serdes_get_prtcl(sd
, cfg
, lane
);
122 if (unlikely(lane_prtcl
>= SERDES_PRCTL_COUNT
))
123 debug("Unknown SerDes lane protocol %d\n", lane_prtcl
);
125 serdes_prtcl_map
[lane_prtcl
] = 1;
128 /* Set the first element to indicate serdes has been initialized */
129 serdes_prtcl_map
[NONE
] = 1;
132 void fsl_serdes_init(void)
134 #ifdef CONFIG_SYS_FSL_SRDS_1
135 serdes_init(FSL_SRDS_1
,
136 CONFIG_SYS_FSL_SERDES_ADDR
,
137 FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK
,
138 FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT
,
141 #ifdef CONFIG_SYS_FSL_SRDS_2
142 serdes_init(FSL_SRDS_2
,
143 CONFIG_SYS_FSL_SERDES_ADDR
,
144 FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_MASK
,
145 FSL_CHASSIS2_RCWSR4_SRDS2_PRTCL_SHIFT
,