Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 4 | * Author: Prabhakar Kushwaha <prabhakar@freescale.com> |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <config.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/immap_85xx.h> |
| 11 | #include <asm/fsl_serdes.h> |
| 12 | |
| 13 | #define SRDS1_MAX_LANES 4 |
| 14 | #define SRDS2_MAX_LANES 2 |
| 15 | |
| 16 | static u32 serdes1_prtcl_map, serdes2_prtcl_map; |
| 17 | |
| 18 | static const u8 serdes1_cfg_tbl[][SRDS1_MAX_LANES] = { |
| 19 | [0x00] = {NONE, NONE, NONE, NONE}, |
| 20 | [0x01] = {PCIE1, PCIE2, SGMII_TSEC2, SGMII_TSEC3}, |
| 21 | [0x02] = {PCIE1, SGMII_TSEC1, SGMII_TSEC2, SGMII_TSEC3}, |
| 22 | [0x03] = {NONE, SGMII_TSEC1, SGMII_TSEC2, SGMII_TSEC3}, |
| 23 | }; |
| 24 | |
| 25 | static const u8 serdes2_cfg_tbl[][SRDS2_MAX_LANES] = { |
| 26 | [0x00] = {NONE, NONE}, |
| 27 | [0x01] = {SATA1, SATA2}, |
| 28 | [0x02] = {SATA1, SATA2}, |
| 29 | [0x03] = {PCIE1, PCIE2}, |
| 30 | }; |
| 31 | |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 32 | int is_serdes_configured(enum srds_prtcl device) |
| 33 | { |
Hou Zhiqiang | b435ae9 | 2016-08-02 19:03:22 +0800 | [diff] [blame] | 34 | int ret; |
| 35 | |
| 36 | if (!(serdes1_prtcl_map & (1 << NONE))) |
| 37 | fsl_serdes_init(); |
| 38 | |
| 39 | ret = (1 << device) & serdes1_prtcl_map; |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 40 | |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | |
Hou Zhiqiang | b435ae9 | 2016-08-02 19:03:22 +0800 | [diff] [blame] | 44 | if (!(serdes2_prtcl_map & (1 << NONE))) |
| 45 | fsl_serdes_init(); |
| 46 | |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 47 | return (1 << device) & serdes2_prtcl_map; |
| 48 | } |
| 49 | |
| 50 | void fsl_serdes_init(void) |
| 51 | { |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 52 | ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR; |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 53 | u32 pordevsr = in_be32(&gur->pordevsr); |
| 54 | u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> |
| 55 | MPC85xx_PORDEVSR_IO_SEL_SHIFT; |
| 56 | int lane; |
| 57 | |
Hou Zhiqiang | b435ae9 | 2016-08-02 19:03:22 +0800 | [diff] [blame] | 58 | if (serdes1_prtcl_map & (1 << NONE) && |
| 59 | serdes2_prtcl_map & (1 << NONE)) |
| 60 | return; |
| 61 | |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 62 | debug("PORDEVSR[IO_SEL_SRDS] = %x\n", srds_cfg); |
| 63 | |
Axel Lin | ab95b09 | 2013-05-26 15:00:30 +0800 | [diff] [blame] | 64 | if (srds_cfg >= ARRAY_SIZE(serdes1_cfg_tbl)) { |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 65 | printf("Invalid PORDEVSR[IO_SEL_SRDS] = %d\n", srds_cfg); |
| 66 | return; |
| 67 | } |
| 68 | for (lane = 0; lane < SRDS1_MAX_LANES; lane++) { |
| 69 | enum srds_prtcl lane_prtcl = serdes1_cfg_tbl[srds_cfg][lane]; |
| 70 | serdes1_prtcl_map |= (1 << lane_prtcl); |
| 71 | } |
| 72 | |
Hou Zhiqiang | b435ae9 | 2016-08-02 19:03:22 +0800 | [diff] [blame] | 73 | /* Set the first bit to indicate serdes has been initialized */ |
| 74 | serdes1_prtcl_map |= (1 << NONE); |
| 75 | |
Axel Lin | ab95b09 | 2013-05-26 15:00:30 +0800 | [diff] [blame] | 76 | if (srds_cfg >= ARRAY_SIZE(serdes2_cfg_tbl)) { |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 77 | printf("Invalid PORDEVSR[IO_SEL_SRDS] = %d\n", srds_cfg); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | for (lane = 0; lane < SRDS2_MAX_LANES; lane++) { |
| 82 | enum srds_prtcl lane_prtcl = serdes2_cfg_tbl[srds_cfg][lane]; |
| 83 | serdes2_prtcl_map |= (1 << lane_prtcl); |
| 84 | } |
Hou Zhiqiang | b435ae9 | 2016-08-02 19:03:22 +0800 | [diff] [blame] | 85 | |
| 86 | /* Set the first bit to indicate serdes has been initialized */ |
| 87 | serdes2_prtcl_map |= (1 << NONE); |
Prabhakar Kushwaha | 934e6ed | 2011-01-20 16:34:41 +0530 | [diff] [blame] | 88 | } |