blob: bbe4a0dd62b0d7ff1f9644514ae2c13c99b58a78 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hu1a258072013-07-04 17:30:36 +08002/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Mingkai Hu1a258072013-07-04 17:30:36 +08004 */
5
6#include <config.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Mingkai Hu1a258072013-07-04 17:30:36 +08008#include <asm/io.h>
9#include <asm/immap_85xx.h>
10#include <asm/fsl_serdes.h>
11
12#define SRDS1_MAX_LANES 4
13
14static u32 serdes1_prtcl_map;
15
16struct serdes_config {
17 u32 protocol;
18 u8 lanes[SRDS1_MAX_LANES];
19};
20
21static const struct serdes_config serdes1_cfg_tbl[] = {
22 /* SerDes 1 */
23 {1, {PCIE1, PCIE1, PCIE1, PCIE1} },
24 {2, {PCIE1, PCIE1, PCIE1, PCIE1} },
25 {3, {PCIE1, PCIE1, NONE, NONE} },
26 {4, {PCIE1, PCIE1, NONE, NONE} },
27 {5, {PCIE1, NONE, NONE, NONE} },
28 {6, {PCIE1, NONE, NONE, NONE} },
29 {}
30};
31
32int is_serdes_configured(enum srds_prtcl device)
33{
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080034 if (!(serdes1_prtcl_map & (1 << NONE)))
35 fsl_serdes_init();
36
Mingkai Hu1a258072013-07-04 17:30:36 +080037 return (1 << device) & serdes1_prtcl_map;
38}
39
40void fsl_serdes_init(void)
41{
Tom Rinid5c3bf22022-10-28 20:27:12 -040042 ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR;
Mingkai Hu1a258072013-07-04 17:30:36 +080043 u32 pordevsr = in_be32(&gur->pordevsr);
44 u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
45 MPC85xx_PORDEVSR_IO_SEL_SHIFT;
46 const struct serdes_config *ptr;
47 int lane;
48
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080049 if (serdes1_prtcl_map & (1 << NONE))
50 return;
51
Mingkai Hu1a258072013-07-04 17:30:36 +080052 debug("PORDEVSR[IO_SEL_SRDS] = %x\n", srds_cfg);
53
54 if (srds_cfg > ARRAY_SIZE(serdes1_cfg_tbl)) {
55 printf("Invalid PORDEVSR[IO_SEL_SRDS] = %d\n", srds_cfg);
56 return;
57 }
58
59 ptr = &serdes1_cfg_tbl[srds_cfg];
60 if (!ptr->protocol)
61 return;
62
63 for (lane = 0; lane < SRDS1_MAX_LANES; lane++) {
64 enum srds_prtcl lane_prtcl = ptr->lanes[lane];
65 serdes1_prtcl_map |= (1 << lane_prtcl);
66 }
Hou Zhiqiangb435ae92016-08-02 19:03:22 +080067
68 /* Set the first bit to indicate serdes has been initialized */
69 serdes1_prtcl_map |= (1 << NONE);
Mingkai Hu1a258072013-07-04 17:30:36 +080070}