Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 2 | /* |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 3 | * Copyright 2011-2015 Freescale Semiconductor, Inc. |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 4 | */ |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 5 | #include <errno.h> |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame^] | 7 | #include <net.h> |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 8 | #include <asm/io.h> |
Simon Glass | e3ee2fb | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 9 | #include <fdt_support.h> |
Claudiu Manoil | de9ad7a | 2014-09-05 13:52:36 +0800 | [diff] [blame] | 10 | #include <fsl_mdio.h> |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 11 | #ifdef CONFIG_FSL_LAYERSCAPE |
| 12 | #include <asm/arch/fsl_serdes.h> |
| 13 | #else |
| 14 | #include <asm/fsl_serdes.h> |
| 15 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 16 | |
| 17 | #include "fm.h" |
| 18 | |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 19 | #ifndef CONFIG_DM_ETH |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 20 | struct fm_eth_info fm_info[] = { |
| 21 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 1) |
| 22 | FM_DTSEC_INFO_INITIALIZER(1, 1), |
| 23 | #endif |
| 24 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 2) |
| 25 | FM_DTSEC_INFO_INITIALIZER(1, 2), |
| 26 | #endif |
| 27 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 3) |
| 28 | FM_DTSEC_INFO_INITIALIZER(1, 3), |
| 29 | #endif |
| 30 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 4) |
| 31 | FM_DTSEC_INFO_INITIALIZER(1, 4), |
| 32 | #endif |
| 33 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 5) |
| 34 | FM_DTSEC_INFO_INITIALIZER(1, 5), |
| 35 | #endif |
York Sun | 9941a22 | 2012-10-08 07:44:19 +0000 | [diff] [blame] | 36 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 6) |
| 37 | FM_DTSEC_INFO_INITIALIZER(1, 6), |
| 38 | #endif |
| 39 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 7) |
| 40 | FM_DTSEC_INFO_INITIALIZER(1, 9), |
| 41 | #endif |
| 42 | #if (CONFIG_SYS_NUM_FM1_DTSEC >= 8) |
| 43 | FM_DTSEC_INFO_INITIALIZER(1, 10), |
| 44 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 45 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 1) |
| 46 | FM_DTSEC_INFO_INITIALIZER(2, 1), |
| 47 | #endif |
| 48 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 2) |
| 49 | FM_DTSEC_INFO_INITIALIZER(2, 2), |
| 50 | #endif |
| 51 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 3) |
| 52 | FM_DTSEC_INFO_INITIALIZER(2, 3), |
| 53 | #endif |
| 54 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 4) |
| 55 | FM_DTSEC_INFO_INITIALIZER(2, 4), |
| 56 | #endif |
Timur Tabi | 7920fb1 | 2012-08-14 06:47:21 +0000 | [diff] [blame] | 57 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 5) |
| 58 | FM_DTSEC_INFO_INITIALIZER(2, 5), |
| 59 | #endif |
York Sun | 9941a22 | 2012-10-08 07:44:19 +0000 | [diff] [blame] | 60 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 6) |
| 61 | FM_DTSEC_INFO_INITIALIZER(2, 6), |
| 62 | #endif |
| 63 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 7) |
| 64 | FM_DTSEC_INFO_INITIALIZER(2, 9), |
| 65 | #endif |
| 66 | #if (CONFIG_SYS_NUM_FM2_DTSEC >= 8) |
| 67 | FM_DTSEC_INFO_INITIALIZER(2, 10), |
| 68 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 69 | #if (CONFIG_SYS_NUM_FM1_10GEC >= 1) |
| 70 | FM_TGEC_INFO_INITIALIZER(1, 1), |
| 71 | #endif |
Shaohui Xie | f25c70c | 2013-03-25 07:33:17 +0000 | [diff] [blame] | 72 | #if (CONFIG_SYS_NUM_FM1_10GEC >= 2) |
| 73 | FM_TGEC_INFO_INITIALIZER(1, 2), |
| 74 | #endif |
Shengzhou Liu | 4227e49 | 2013-11-22 17:39:09 +0800 | [diff] [blame] | 75 | #if (CONFIG_SYS_NUM_FM1_10GEC >= 3) |
| 76 | FM_TGEC_INFO_INITIALIZER2(1, 3), |
| 77 | #endif |
| 78 | #if (CONFIG_SYS_NUM_FM1_10GEC >= 4) |
| 79 | FM_TGEC_INFO_INITIALIZER2(1, 4), |
| 80 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 81 | #if (CONFIG_SYS_NUM_FM2_10GEC >= 1) |
| 82 | FM_TGEC_INFO_INITIALIZER(2, 1), |
| 83 | #endif |
Shaohui Xie | f25c70c | 2013-03-25 07:33:17 +0000 | [diff] [blame] | 84 | #if (CONFIG_SYS_NUM_FM2_10GEC >= 2) |
| 85 | FM_TGEC_INFO_INITIALIZER(2, 2), |
| 86 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | int fm_standard_init(bd_t *bis) |
| 90 | { |
| 91 | int i; |
| 92 | struct ccsr_fman *reg; |
| 93 | |
| 94 | reg = (void *)CONFIG_SYS_FSL_FM1_ADDR; |
| 95 | if (fm_init_common(0, reg)) |
| 96 | return 0; |
| 97 | |
| 98 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) { |
| 99 | if ((fm_info[i].enabled) && (fm_info[i].index == 1)) |
| 100 | fm_eth_initialize(reg, &fm_info[i]); |
| 101 | } |
| 102 | |
| 103 | #if (CONFIG_SYS_NUM_FMAN == 2) |
| 104 | reg = (void *)CONFIG_SYS_FSL_FM2_ADDR; |
| 105 | if (fm_init_common(1, reg)) |
| 106 | return 0; |
| 107 | |
| 108 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) { |
| 109 | if ((fm_info[i].enabled) && (fm_info[i].index == 2)) |
| 110 | fm_eth_initialize(reg, &fm_info[i]); |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | /* simple linear search to map from port to array index */ |
| 118 | static int fm_port_to_index(enum fm_port port) |
| 119 | { |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) { |
| 123 | if (fm_info[i].port == port) |
| 124 | return i; |
| 125 | } |
| 126 | |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Determine if an interface is actually active based on HW config |
| 132 | * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NONE if |
| 133 | * the interface is not active based on HW cfg of the SoC |
| 134 | */ |
| 135 | void fman_enet_init(void) |
| 136 | { |
| 137 | int i; |
| 138 | |
| 139 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) { |
| 140 | phy_interface_t enet_if; |
| 141 | |
| 142 | enet_if = fman_port_enet_if(fm_info[i].port); |
| 143 | if (enet_if != PHY_INTERFACE_MODE_NONE) { |
| 144 | fm_info[i].enabled = 1; |
| 145 | fm_info[i].enet_if = enet_if; |
| 146 | } else { |
| 147 | fm_info[i].enabled = 0; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return ; |
| 152 | } |
| 153 | |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 154 | void fm_disable_port(enum fm_port port) |
| 155 | { |
| 156 | int i = fm_port_to_index(port); |
| 157 | |
Rotariu Marian-Cristian | 092af03 | 2014-05-19 10:59:52 +0300 | [diff] [blame] | 158 | if (i == -1) |
| 159 | return; |
| 160 | |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 161 | fm_info[i].enabled = 0; |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 162 | #ifndef CONFIG_SYS_FMAN_V3 |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 163 | fman_disable_port(port); |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 164 | #endif |
Kumar Gala | 5536d92 | 2011-09-14 12:01:35 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Valentin Longchamp | 51b2ca3 | 2013-10-18 11:47:21 +0200 | [diff] [blame] | 167 | void fm_enable_port(enum fm_port port) |
| 168 | { |
| 169 | int i = fm_port_to_index(port); |
| 170 | |
Rotariu Marian-Cristian | 092af03 | 2014-05-19 10:59:52 +0300 | [diff] [blame] | 171 | if (i == -1) |
| 172 | return; |
| 173 | |
Valentin Longchamp | 51b2ca3 | 2013-10-18 11:47:21 +0200 | [diff] [blame] | 174 | fm_info[i].enabled = 1; |
| 175 | fman_enable_port(port); |
| 176 | } |
| 177 | |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 178 | void fm_info_set_mdio(enum fm_port port, struct mii_dev *bus) |
| 179 | { |
| 180 | int i = fm_port_to_index(port); |
| 181 | |
| 182 | if (i == -1) |
| 183 | return; |
| 184 | |
| 185 | fm_info[i].bus = bus; |
| 186 | } |
| 187 | |
| 188 | void fm_info_set_phy_address(enum fm_port port, int address) |
| 189 | { |
| 190 | int i = fm_port_to_index(port); |
| 191 | |
| 192 | if (i == -1) |
| 193 | return; |
| 194 | |
| 195 | fm_info[i].phy_addr = address; |
| 196 | } |
| 197 | |
| 198 | /* |
Timur Tabi | bad16ea | 2012-08-14 06:47:22 +0000 | [diff] [blame] | 199 | * Returns the PHY address for a given Fman port |
| 200 | * |
| 201 | * The port must be set via a prior call to fm_info_set_phy_address(). |
| 202 | * A negative error code is returned if the port is invalid. |
| 203 | */ |
| 204 | int fm_info_get_phy_address(enum fm_port port) |
| 205 | { |
| 206 | int i = fm_port_to_index(port); |
| 207 | |
| 208 | if (i == -1) |
| 209 | return -1; |
| 210 | |
| 211 | return fm_info[i].phy_addr; |
| 212 | } |
| 213 | |
| 214 | /* |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 215 | * Returns the type of the data interface between the given MAC and its PHY. |
| 216 | * This is typically determined by the RCW. |
| 217 | */ |
| 218 | phy_interface_t fm_info_get_enet_if(enum fm_port port) |
| 219 | { |
| 220 | int i = fm_port_to_index(port); |
| 221 | |
| 222 | if (i == -1) |
| 223 | return PHY_INTERFACE_MODE_NONE; |
| 224 | |
| 225 | if (fm_info[i].enabled) |
| 226 | return fm_info[i].enet_if; |
| 227 | |
| 228 | return PHY_INTERFACE_MODE_NONE; |
| 229 | } |
| 230 | |
| 231 | static void |
| 232 | __def_board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa, |
| 233 | enum fm_port port, int offset) |
| 234 | { |
| 235 | return ; |
| 236 | } |
| 237 | |
| 238 | void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa, |
| 239 | enum fm_port port, int offset) |
| 240 | __attribute__((weak, alias("__def_board_ft_fman_fixup_port"))); |
| 241 | |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 242 | int ft_fixup_port(void *blob, struct fm_eth_info *info, char *prop) |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 243 | { |
Timur Tabi | 52effa6 | 2012-08-14 06:47:24 +0000 | [diff] [blame] | 244 | int off; |
| 245 | uint32_t ph; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 246 | phys_addr_t paddr = CONFIG_SYS_CCSRBAR_PHYS + info->compat_offset; |
Shaohui Xie | acad8b0 | 2015-12-04 10:22:03 +0800 | [diff] [blame] | 247 | #ifndef CONFIG_SYS_FMAN_V3 |
Kumar Gala | 1ec665a | 2011-10-13 14:55:59 -0500 | [diff] [blame] | 248 | u64 dtsec1_addr = (u64)CONFIG_SYS_CCSRBAR_PHYS + |
| 249 | CONFIG_SYS_FSL_FM1_DTSEC1_OFFSET; |
Shaohui Xie | acad8b0 | 2015-12-04 10:22:03 +0800 | [diff] [blame] | 250 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 251 | |
| 252 | off = fdt_node_offset_by_compat_reg(blob, prop, paddr); |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 253 | if (off == -FDT_ERR_NOTFOUND) |
| 254 | return -EINVAL; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 255 | |
| 256 | if (info->enabled) { |
| 257 | fdt_fixup_phy_connection(blob, off, info->enet_if); |
| 258 | board_ft_fman_fixup_port(blob, prop, paddr, info->port, off); |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 259 | return 0; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 260 | } |
| 261 | |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 262 | #ifdef CONFIG_SYS_FMAN_V3 |
Shengzhou Liu | 92fb6ac | 2014-12-03 15:27:03 +0800 | [diff] [blame] | 263 | #ifndef CONFIG_FSL_FM_10GEC_REGULAR_NOTATION |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 264 | /* |
Shengzhou Liu | 92fb6ac | 2014-12-03 15:27:03 +0800 | [diff] [blame] | 265 | * On T2/T4 SoCs, physically FM1_DTSEC9 and FM1_10GEC1 use the same |
| 266 | * dual-role MAC, when FM1_10GEC1 is enabled and FM1_DTSEC9 |
| 267 | * is disabled, ensure that the dual-role MAC is not disabled, |
| 268 | * ditto for other dual-role MACs. |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 269 | */ |
Shengzhou Liu | 4227e49 | 2013-11-22 17:39:09 +0800 | [diff] [blame] | 270 | if (((info->port == FM1_DTSEC9) && (PORT_IS_ENABLED(FM1_10GEC1))) || |
| 271 | ((info->port == FM1_DTSEC10) && (PORT_IS_ENABLED(FM1_10GEC2))) || |
| 272 | ((info->port == FM1_DTSEC1) && (PORT_IS_ENABLED(FM1_10GEC3))) || |
| 273 | ((info->port == FM1_DTSEC2) && (PORT_IS_ENABLED(FM1_10GEC4))) || |
| 274 | ((info->port == FM1_10GEC1) && (PORT_IS_ENABLED(FM1_DTSEC9))) || |
| 275 | ((info->port == FM1_10GEC2) && (PORT_IS_ENABLED(FM1_DTSEC10))) || |
| 276 | ((info->port == FM1_10GEC3) && (PORT_IS_ENABLED(FM1_DTSEC1))) || |
| 277 | ((info->port == FM1_10GEC4) && (PORT_IS_ENABLED(FM1_DTSEC2))) |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 278 | #if (CONFIG_SYS_NUM_FMAN == 2) |
| 279 | || |
| 280 | ((info->port == FM2_DTSEC9) && (PORT_IS_ENABLED(FM2_10GEC1))) || |
| 281 | ((info->port == FM2_DTSEC10) && (PORT_IS_ENABLED(FM2_10GEC2))) || |
| 282 | ((info->port == FM2_10GEC1) && (PORT_IS_ENABLED(FM2_DTSEC9))) || |
| 283 | ((info->port == FM2_10GEC2) && (PORT_IS_ENABLED(FM2_DTSEC10))) |
| 284 | #endif |
Shengzhou Liu | 92fb6ac | 2014-12-03 15:27:03 +0800 | [diff] [blame] | 285 | #else |
| 286 | /* FM1_DTSECx and FM1_10GECx use the same dual-role MAC */ |
| 287 | if (((info->port == FM1_DTSEC1) && (PORT_IS_ENABLED(FM1_10GEC1))) || |
| 288 | ((info->port == FM1_DTSEC2) && (PORT_IS_ENABLED(FM1_10GEC2))) || |
| 289 | ((info->port == FM1_DTSEC3) && (PORT_IS_ENABLED(FM1_10GEC3))) || |
| 290 | ((info->port == FM1_DTSEC4) && (PORT_IS_ENABLED(FM1_10GEC4))) || |
| 291 | ((info->port == FM1_10GEC1) && (PORT_IS_ENABLED(FM1_DTSEC1))) || |
| 292 | ((info->port == FM1_10GEC2) && (PORT_IS_ENABLED(FM1_DTSEC2))) || |
| 293 | ((info->port == FM1_10GEC3) && (PORT_IS_ENABLED(FM1_DTSEC3))) || |
| 294 | ((info->port == FM1_10GEC4) && (PORT_IS_ENABLED(FM1_DTSEC4))) |
| 295 | #endif |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 296 | ) |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 297 | return 0; |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 298 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 299 | /* board code might have caused offset to change */ |
| 300 | off = fdt_node_offset_by_compat_reg(blob, prop, paddr); |
| 301 | |
Shaohui Xie | acad8b0 | 2015-12-04 10:22:03 +0800 | [diff] [blame] | 302 | #ifndef CONFIG_SYS_FMAN_V3 |
Kumar Gala | 1ec665a | 2011-10-13 14:55:59 -0500 | [diff] [blame] | 303 | /* Don't disable FM1-DTSEC1 MAC as its used for MDIO */ |
Timur Tabi | 52effa6 | 2012-08-14 06:47:24 +0000 | [diff] [blame] | 304 | if (paddr != dtsec1_addr) |
Shaohui Xie | acad8b0 | 2015-12-04 10:22:03 +0800 | [diff] [blame] | 305 | #endif |
Timur Tabi | 52effa6 | 2012-08-14 06:47:24 +0000 | [diff] [blame] | 306 | fdt_status_disabled(blob, off); /* disable the MAC node */ |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 307 | |
Timur Tabi | 52effa6 | 2012-08-14 06:47:24 +0000 | [diff] [blame] | 308 | /* disable the fsl,dpa-ethernet node that points to the MAC */ |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 309 | ph = fdt_get_phandle(blob, off); |
| 310 | do_fixup_by_prop(blob, "fsl,fman-mac", &ph, sizeof(ph), |
| 311 | "status", "disabled", strlen("disabled") + 1, 1); |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 312 | |
| 313 | return 0; |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void fdt_fixup_fman_ethernet(void *blob) |
| 317 | { |
| 318 | int i; |
| 319 | |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 320 | #ifdef CONFIG_SYS_FMAN_V3 |
Shengzhou Liu | 84bbe68 | 2014-01-13 15:32:24 +0800 | [diff] [blame] | 321 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 322 | ft_fixup_port(blob, &fm_info[i], "fsl,fman-memac"); |
| 323 | #else |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 324 | for (i = 0; i < ARRAY_SIZE(fm_info); i++) { |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 325 | /* Try the new compatible first. |
| 326 | * If the node is missing, try the old. |
| 327 | */ |
| 328 | if (fm_info[i].type == FM_ETH_1G_E) { |
| 329 | if (ft_fixup_port(blob, &fm_info[i], "fsl,fman-dtsec")) |
| 330 | ft_fixup_port(blob, &fm_info[i], |
| 331 | "fsl,fman-1g-mac"); |
| 332 | } else { |
Zhao Qiang | c47115e | 2018-08-29 11:46:34 +0800 | [diff] [blame] | 333 | if (ft_fixup_port(blob, &fm_info[i], "fsl,fman-xgec") && |
| 334 | ft_fixup_port(blob, &fm_info[i], "fsl,fman-tgec")) |
Igal Liberman | e14ec99 | 2015-08-18 14:47:05 +0300 | [diff] [blame] | 335 | ft_fixup_port(blob, &fm_info[i], |
| 336 | "fsl,fman-10g-mac"); |
| 337 | } |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 338 | } |
Shengzhou Liu | 0348bf8 | 2013-03-25 07:39:29 +0000 | [diff] [blame] | 339 | #endif |
Kumar Gala | 2683c53 | 2011-04-13 08:37:44 -0500 | [diff] [blame] | 340 | } |
Zhao Qiang | 1ae9919 | 2013-09-04 10:11:27 +0800 | [diff] [blame] | 341 | |
| 342 | /*QSGMII Riser Card can work in SGMII mode, but the PHY address is different. |
| 343 | *This function scans which Riser Card being used(QSGMII or SGMII Riser Card), |
| 344 | *then set the correct PHY address |
| 345 | */ |
| 346 | void set_sgmii_phy(struct mii_dev *bus, enum fm_port base_port, |
| 347 | unsigned int port_num, int phy_base_addr) |
| 348 | { |
| 349 | unsigned int regnum = 0; |
| 350 | int qsgmii; |
| 351 | int i; |
| 352 | int phy_real_addr; |
| 353 | |
| 354 | qsgmii = is_qsgmii_riser_card(bus, phy_base_addr, port_num, regnum); |
| 355 | |
| 356 | if (!qsgmii) |
| 357 | return; |
| 358 | |
| 359 | for (i = base_port; i < base_port + port_num; i++) { |
| 360 | if (fm_info_get_enet_if(i) == PHY_INTERFACE_MODE_SGMII) { |
| 361 | phy_real_addr = phy_base_addr + i - base_port; |
| 362 | fm_info_set_phy_address(i, phy_real_addr); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /*to check whether qsgmii riser card is used*/ |
| 368 | int is_qsgmii_riser_card(struct mii_dev *bus, int phy_base_addr, |
| 369 | unsigned int port_num, unsigned regnum) |
| 370 | { |
| 371 | int i; |
| 372 | int val; |
| 373 | |
| 374 | if (!bus) |
| 375 | return 0; |
| 376 | |
| 377 | for (i = phy_base_addr; i < phy_base_addr + port_num; i++) { |
| 378 | val = bus->read(bus, i, MDIO_DEVAD_NONE, regnum); |
| 379 | if (val != MIIM_TIMEOUT) |
| 380 | return 1; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 385 | #endif /* CONFIG_DM_ETH */ |