]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/armv8/fsl-lsch3/fsl_lsch3_serdes.c
Merge branch 'master' of git://www.denx.de/git/u-boot-socfpga
[people/ms/u-boot.git] / arch / arm / cpu / armv8 / fsl-lsch3 / fsl_lsch3_serdes.c
1 /*
2 * Copyright 2015 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/errno.h>
10 #include <asm/arch/fsl_serdes.h>
11 #include <asm/arch-fsl-lsch3/immap_lsch3.h>
12 #include <fsl-mc/ldpaa_wriop.h>
13
14 #ifdef CONFIG_SYS_FSL_SRDS_1
15 static u8 serdes1_prtcl_map[SERDES_PRCTL_COUNT];
16 #endif
17 #ifdef CONFIG_SYS_FSL_SRDS_2
18 static u8 serdes2_prtcl_map[SERDES_PRCTL_COUNT];
19 #endif
20
21 int is_serdes_configured(enum srds_prtcl device)
22 {
23 int ret = 0;
24
25 #ifdef CONFIG_SYS_FSL_SRDS_1
26 ret |= serdes1_prtcl_map[device];
27 #endif
28 #ifdef CONFIG_SYS_FSL_SRDS_2
29 ret |= serdes2_prtcl_map[device];
30 #endif
31
32 return !!ret;
33 }
34
35 int serdes_get_first_lane(u32 sd, enum srds_prtcl device)
36 {
37 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
38 u32 cfg = in_le32(&gur->rcwsr[28]);
39 int i;
40
41 switch (sd) {
42 #ifdef CONFIG_SYS_FSL_SRDS_1
43 case FSL_SRDS_1:
44 cfg &= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
45 cfg >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
46 break;
47 #endif
48 #ifdef CONFIG_SYS_FSL_SRDS_2
49 case FSL_SRDS_2:
50 cfg &= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK;
51 cfg >>= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
52 break;
53 #endif
54 default:
55 printf("invalid SerDes%d\n", sd);
56 break;
57 }
58 /* Is serdes enabled at all? */
59 if (cfg == 0)
60 return -ENODEV;
61
62 for (i = 0; i < SRDS_MAX_LANES; i++) {
63 if (serdes_get_prtcl(sd, cfg, i) == device)
64 return i;
65 }
66
67 return -ENODEV;
68 }
69
70 void serdes_init(u32 sd, u32 sd_addr, u32 sd_prctl_mask, u32 sd_prctl_shift,
71 u8 serdes_prtcl_map[SERDES_PRCTL_COUNT])
72 {
73 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
74 u32 cfg;
75 int lane;
76
77 memset(serdes_prtcl_map, 0, sizeof(serdes_prtcl_map));
78
79 cfg = in_le32(&gur->rcwsr[28]) & sd_prctl_mask;
80 cfg >>= sd_prctl_shift;
81 printf("Using SERDES%d Protocol: %d (0x%x)\n", sd + 1, cfg, cfg);
82
83 if (!is_serdes_prtcl_valid(sd, cfg))
84 printf("SERDES%d[PRTCL] = 0x%x is not valid\n", sd + 1, cfg);
85
86 for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
87 enum srds_prtcl lane_prtcl = serdes_get_prtcl(sd, cfg, lane);
88 if (unlikely(lane_prtcl >= SERDES_PRCTL_COUNT))
89 debug("Unknown SerDes lane protocol %d\n", lane_prtcl);
90 else {
91 serdes_prtcl_map[lane_prtcl] = 1;
92 #ifdef CONFIG_FSL_MC_ENET
93 wriop_init_dpmac(sd, lane + 1, (int)lane_prtcl);
94 #endif
95 }
96 }
97 }
98
99 void fsl_serdes_init(void)
100 {
101 #ifdef CONFIG_SYS_FSL_SRDS_1
102 serdes_init(FSL_SRDS_1,
103 CONFIG_SYS_FSL_LSCH3_SERDES_ADDR,
104 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK,
105 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT,
106 serdes1_prtcl_map);
107 #endif
108 #ifdef CONFIG_SYS_FSL_SRDS_2
109 serdes_init(FSL_SRDS_2,
110 CONFIG_SYS_FSL_LSCH3_SERDES_ADDR + FSL_SRDS_2 * 0x10000,
111 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK,
112 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT,
113 serdes2_prtcl_map);
114 #endif
115 }