1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
23818db43SKumar Gala /*
33818db43SKumar Gala * Copyright 2010 Freescale Semiconductor, Inc.
43818db43SKumar Gala */
53818db43SKumar Gala
63818db43SKumar Gala #include <config.h>
73818db43SKumar Gala #include <common.h>
83818db43SKumar Gala #include <asm/io.h>
93818db43SKumar Gala #include <asm/immap_85xx.h>
103818db43SKumar Gala #include <asm/fsl_serdes.h>
113818db43SKumar Gala
123818db43SKumar Gala #define SRDS1_MAX_LANES 4
133818db43SKumar Gala
143818db43SKumar Gala static u32 serdes1_prtcl_map;
153818db43SKumar Gala
163818db43SKumar Gala static u8 serdes1_cfg_tbl[][SRDS1_MAX_LANES] = {
173818db43SKumar Gala [0x0] = {PCIE1, NONE, NONE, NONE},
183818db43SKumar Gala [0x2] = {PCIE1, PCIE2, PCIE3, PCIE3},
193818db43SKumar Gala [0x4] = {PCIE1, PCIE1, PCIE3, PCIE3},
203818db43SKumar Gala [0x6] = {PCIE1, PCIE1, PCIE1, PCIE1},
213818db43SKumar Gala [0x7] = {SRIO2, SRIO1, NONE, NONE},
223818db43SKumar Gala [0x8] = {SRIO2, SRIO2, SRIO2, SRIO2},
233818db43SKumar Gala [0x9] = {SRIO2, SRIO2, SRIO2, SRIO2},
243818db43SKumar Gala [0xa] = {SRIO2, SRIO2, SRIO2, SRIO2},
253818db43SKumar Gala [0xb] = {SRIO2, SRIO1, SGMII_TSEC2, SGMII_TSEC3},
263818db43SKumar Gala [0xc] = {SRIO2, SRIO1, SGMII_TSEC2, SGMII_TSEC3},
273818db43SKumar Gala [0xd] = {PCIE1, SRIO1, SGMII_TSEC2, SGMII_TSEC3},
283818db43SKumar Gala [0xe] = {PCIE1, PCIE2, SGMII_TSEC2, SGMII_TSEC3},
293818db43SKumar Gala [0xf] = {PCIE1, PCIE1, SGMII_TSEC2, SGMII_TSEC3},
303818db43SKumar Gala };
313818db43SKumar Gala
is_serdes_configured(enum srds_prtcl prtcl)323818db43SKumar Gala int is_serdes_configured(enum srds_prtcl prtcl)
333818db43SKumar Gala {
3471fe2225SHou Zhiqiang if (!(serdes1_prtcl_map & (1 << NONE)))
3571fe2225SHou Zhiqiang fsl_serdes_init();
3671fe2225SHou Zhiqiang
373818db43SKumar Gala return (1 << prtcl) & serdes1_prtcl_map;
383818db43SKumar Gala }
393818db43SKumar Gala
fsl_serdes_init(void)403818db43SKumar Gala void fsl_serdes_init(void)
413818db43SKumar Gala {
423818db43SKumar Gala ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
433818db43SKumar Gala u32 pordevsr = in_be32(&gur->pordevsr);
443818db43SKumar Gala u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
453818db43SKumar Gala MPC85xx_PORDEVSR_IO_SEL_SHIFT;
463818db43SKumar Gala int lane;
473818db43SKumar Gala
4871fe2225SHou Zhiqiang if (serdes1_prtcl_map & (1 << NONE))
4971fe2225SHou Zhiqiang return;
5071fe2225SHou Zhiqiang
513818db43SKumar Gala debug("PORDEVSR[IO_SEL_SRDS] = %x\n", srds_cfg);
523818db43SKumar Gala
53e51e47d3SAxel Lin if (srds_cfg >= ARRAY_SIZE(serdes1_cfg_tbl)) {
543818db43SKumar Gala printf("Invalid PORDEVSR[IO_SEL_SRDS] = %d\n", srds_cfg);
553818db43SKumar Gala return;
563818db43SKumar Gala }
573818db43SKumar Gala
583818db43SKumar Gala for (lane = 0; lane < SRDS1_MAX_LANES; lane++) {
593818db43SKumar Gala enum srds_prtcl lane_prtcl = serdes1_cfg_tbl[srds_cfg][lane];
603818db43SKumar Gala serdes1_prtcl_map |= (1 << lane_prtcl);
613818db43SKumar Gala }
6271fe2225SHou Zhiqiang
6371fe2225SHou Zhiqiang /* Set the first bit to indicate serdes has been initialized */
6471fe2225SHou Zhiqiang serdes1_prtcl_map |= (1 << NONE);
653818db43SKumar Gala }
66