blob: 7a8f653727efdc60f6d5b22c894d92ad428719fb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Roy Zang1de20b02011-02-03 22:14:19 -06002/*
3 * Copyright 2010-2011 Freescale Semiconductor, Inc.
4 * Author: Roy Zang <tie-fei.zang@freescale.com>
Roy Zang1de20b02011-02-03 22:14:19 -06005 */
6
7#include <config.h>
8#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Roy Zang1de20b02011-02-03 22:14:19 -060010#include <asm/io.h>
11#include <asm/immap_85xx.h>
12#include <asm/fsl_serdes.h>
13
14#define SRDS1_MAX_LANES 4
15
16static u32 serdes1_prtcl_map;
17
18static const u8 serdes1_cfg_tbl[][SRDS1_MAX_LANES] = {
19 [0x00] = {PCIE1, PCIE2, NONE, NONE},
20 [0x01] = {PCIE1, PCIE2, PCIE3, NONE},
21 [0x02] = {PCIE1, PCIE2, PCIE3, SGMII_FM1_DTSEC2},
22 [0x03] = {PCIE1, PCIE2, SGMII_FM1_DTSEC1, SGMII_FM1_DTSEC2},
23};
24
25int is_serdes_configured(enum srds_prtcl device)
26{
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080027 int ret;
28
29 if (!(serdes1_prtcl_map & (1 << NONE)))
30 fsl_serdes_init();
31
32 ret = (1 << device) & serdes1_prtcl_map;
Roy Zang1de20b02011-02-03 22:14:19 -060033 return ret;
34}
35
36void fsl_serdes_init(void)
37{
Tom Rinid5c3bf22022-10-28 20:27:12 -040038 ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR;
Roy Zang1de20b02011-02-03 22:14:19 -060039 u32 pordevsr = in_be32(&gur->pordevsr);
40 u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
41 MPC85xx_PORDEVSR_IO_SEL_SHIFT;
42 int lane;
43
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080044 if (serdes1_prtcl_map & (1 << NONE))
45 return;
46
Roy Zang1de20b02011-02-03 22:14:19 -060047 debug("PORDEVSR[IO_SEL_SRDS] = %x\n", srds_cfg);
48
Axel Linab95b092013-05-26 15:00:30 +080049 if (srds_cfg >= ARRAY_SIZE(serdes1_cfg_tbl)) {
Roy Zang1de20b02011-02-03 22:14:19 -060050 printf("Invalid PORDEVSR[IO_SEL_SRDS] = %d\n", srds_cfg);
51 return;
52 }
53 for (lane = 0; lane < SRDS1_MAX_LANES; lane++) {
54 enum srds_prtcl lane_prtcl = serdes1_cfg_tbl[srds_cfg][lane];
55 serdes1_prtcl_map |= (1 << lane_prtcl);
56 }
57
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080058 /* Set the first bit to indicate serdes has been initialized */
59 serdes1_prtcl_map |= (1 << NONE);
Roy Zang1de20b02011-02-03 22:14:19 -060060}