Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <netdev.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 10 | #include <hwconfig.h> |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 11 | #include <fsl_mdio.h> |
| 12 | #include <malloc.h> |
| 13 | #include <fm_eth.h> |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 14 | #include <i2c.h> |
| 15 | #include <miiphy.h> |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 16 | #include <fsl-mc/fsl_mc.h> |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 17 | #include <fsl-mc/ldpaa_wriop.h> |
| 18 | |
| 19 | #include "../common/qixis.h" |
| 20 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 21 | #include "ls2080aqds_qixis.h" |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 22 | |
Pratiyush Mohan Srivastava | 9abba11 | 2016-01-20 12:29:03 +0530 | [diff] [blame] | 23 | #define MC_BOOT_ENV_VAR "mcinitcmd" |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 24 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 25 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 26 | /* - In LS2080A there are only 16 SERDES lanes, spread across 2 SERDES banks. |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 27 | * Bank 1 -> Lanes A, B, C, D, E, F, G, H |
| 28 | * Bank 2 -> Lanes A,B, C, D, E, F, G, H |
| 29 | */ |
| 30 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 31 | /* Mapping of 16 SERDES lanes to LS2080A QDS board slots. A value of '0' here |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 32 | * means that the mapping must be determined dynamically, or that the lane |
| 33 | * maps to something other than a board slot. |
| 34 | */ |
| 35 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 36 | static u8 lane_to_slot_fsm1[] = { |
| 37 | 0, 0, 0, 0, 0, 0, 0, 0 |
| 38 | }; |
| 39 | |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 40 | static u8 lane_to_slot_fsm2[] = { |
| 41 | 0, 0, 0, 0, 0, 0, 0, 0 |
| 42 | }; |
| 43 | |
| 44 | /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs |
| 45 | * housed. |
| 46 | */ |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 47 | |
| 48 | static int xqsgii_riser_phy_addr[] = { |
| 49 | XQSGMII_CARD_PHY1_PORT0_ADDR, |
| 50 | XQSGMII_CARD_PHY2_PORT0_ADDR, |
| 51 | XQSGMII_CARD_PHY3_PORT0_ADDR, |
| 52 | XQSGMII_CARD_PHY4_PORT0_ADDR, |
| 53 | XQSGMII_CARD_PHY3_PORT2_ADDR, |
| 54 | XQSGMII_CARD_PHY1_PORT2_ADDR, |
| 55 | XQSGMII_CARD_PHY4_PORT2_ADDR, |
| 56 | XQSGMII_CARD_PHY2_PORT2_ADDR, |
| 57 | }; |
| 58 | |
| 59 | static int sgmii_riser_phy_addr[] = { |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 60 | SGMII_CARD_PORT1_PHY_ADDR, |
| 61 | SGMII_CARD_PORT2_PHY_ADDR, |
| 62 | SGMII_CARD_PORT3_PHY_ADDR, |
| 63 | SGMII_CARD_PORT4_PHY_ADDR, |
| 64 | }; |
| 65 | |
| 66 | /* Slot2 does not have EMI connections */ |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 67 | #define EMI_NONE 0xFF |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 68 | #define EMI1_SLOT1 0 |
| 69 | #define EMI1_SLOT2 1 |
| 70 | #define EMI1_SLOT3 2 |
| 71 | #define EMI1_SLOT4 3 |
| 72 | #define EMI1_SLOT5 4 |
| 73 | #define EMI1_SLOT6 5 |
| 74 | #define EMI2 6 |
Prabhakar Kushwaha | 782d666 | 2015-05-28 14:54:00 +0530 | [diff] [blame] | 75 | #define SFP_TX 0 |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 76 | |
| 77 | static const char * const mdio_names[] = { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 78 | "LS2080A_QDS_MDIO0", |
| 79 | "LS2080A_QDS_MDIO1", |
| 80 | "LS2080A_QDS_MDIO2", |
| 81 | "LS2080A_QDS_MDIO3", |
| 82 | "LS2080A_QDS_MDIO4", |
| 83 | "LS2080A_QDS_MDIO5", |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 84 | DEFAULT_WRIOP_MDIO2_NAME, |
| 85 | }; |
| 86 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 87 | struct ls2080a_qds_mdio { |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 88 | u8 muxval; |
| 89 | struct mii_dev *realbus; |
| 90 | }; |
| 91 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 92 | static void sgmii_configure_repeater(int serdes_port) |
| 93 | { |
| 94 | struct mii_dev *bus; |
| 95 | uint8_t a = 0xf; |
| 96 | int i, j, ret; |
| 97 | int dpmac_id = 0, dpmac, mii_bus = 0; |
| 98 | unsigned short value; |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 99 | char dev[2][20] = {"LS2080A_QDS_MDIO0", "LS2080A_QDS_MDIO3"}; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 100 | uint8_t i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5f, 0x60}; |
| 101 | |
| 102 | uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7}; |
| 103 | uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84}; |
| 104 | uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7}; |
| 105 | uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84}; |
| 106 | |
| 107 | int *riser_phy_addr = &xqsgii_riser_phy_addr[0]; |
| 108 | |
| 109 | /* Set I2c to Slot 1 */ |
| 110 | i2c_write(0x77, 0, 0, &a, 1); |
| 111 | |
| 112 | for (dpmac = 0; dpmac < 8; dpmac++) { |
| 113 | /* Check the PHY status */ |
| 114 | switch (serdes_port) { |
| 115 | case 1: |
| 116 | mii_bus = 0; |
| 117 | dpmac_id = dpmac + 1; |
| 118 | break; |
| 119 | case 2: |
| 120 | mii_bus = 1; |
| 121 | dpmac_id = dpmac + 9; |
| 122 | a = 0xb; |
| 123 | i2c_write(0x76, 0, 0, &a, 1); |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | ret = miiphy_set_current_dev(dev[mii_bus]); |
| 128 | if (ret > 0) |
| 129 | goto error; |
| 130 | |
| 131 | bus = mdio_get_current_dev(); |
| 132 | debug("Reading from bus %s\n", bus->name); |
| 133 | |
| 134 | ret = miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f, |
| 135 | 3); |
| 136 | if (ret > 0) |
| 137 | goto error; |
| 138 | |
| 139 | mdelay(10); |
| 140 | ret = miiphy_read(dev[mii_bus], riser_phy_addr[dpmac], 0x11, |
| 141 | &value); |
| 142 | if (ret > 0) |
| 143 | goto error; |
| 144 | |
| 145 | mdelay(10); |
| 146 | |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 147 | if ((value & 0xfff) == 0x401) { |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 148 | printf("DPMAC %d:PHY is ..... Configured\n", dpmac_id); |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 149 | miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], |
| 150 | 0x1f, 0); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 151 | continue; |
| 152 | } |
| 153 | |
| 154 | for (i = 0; i < 4; i++) { |
| 155 | for (j = 0; j < 4; j++) { |
| 156 | a = 0x18; |
| 157 | i2c_write(i2c_addr[dpmac], 6, 1, &a, 1); |
| 158 | a = 0x38; |
| 159 | i2c_write(i2c_addr[dpmac], 4, 1, &a, 1); |
| 160 | a = 0x4; |
| 161 | i2c_write(i2c_addr[dpmac], 8, 1, &a, 1); |
| 162 | |
| 163 | i2c_write(i2c_addr[dpmac], 0xf, 1, |
| 164 | &ch_a_eq[i], 1); |
| 165 | i2c_write(i2c_addr[dpmac], 0x11, 1, |
| 166 | &ch_a_ctl2[j], 1); |
| 167 | |
| 168 | i2c_write(i2c_addr[dpmac], 0x16, 1, |
| 169 | &ch_b_eq[i], 1); |
| 170 | i2c_write(i2c_addr[dpmac], 0x18, 1, |
| 171 | &ch_b_ctl2[j], 1); |
| 172 | |
| 173 | a = 0x14; |
| 174 | i2c_write(i2c_addr[dpmac], 0x23, 1, &a, 1); |
| 175 | a = 0xb5; |
| 176 | i2c_write(i2c_addr[dpmac], 0x2d, 1, &a, 1); |
| 177 | a = 0x20; |
| 178 | i2c_write(i2c_addr[dpmac], 4, 1, &a, 1); |
| 179 | mdelay(100); |
| 180 | ret = miiphy_read(dev[mii_bus], |
| 181 | riser_phy_addr[dpmac], |
| 182 | 0x11, &value); |
| 183 | if (ret > 0) |
| 184 | goto error; |
| 185 | |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 186 | mdelay(100); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 187 | ret = miiphy_read(dev[mii_bus], |
| 188 | riser_phy_addr[dpmac], |
| 189 | 0x11, &value); |
| 190 | if (ret > 0) |
| 191 | goto error; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 192 | |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 193 | if ((value & 0xfff) == 0x401) { |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 194 | printf("DPMAC %d :PHY is configured ", |
| 195 | dpmac_id); |
| 196 | printf("after setting repeater 0x%x\n", |
| 197 | value); |
| 198 | i = 5; |
| 199 | j = 5; |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 200 | } else { |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 201 | printf("DPMAC %d :PHY is failed to ", |
| 202 | dpmac_id); |
| 203 | printf("configure the repeater 0x%x\n", |
| 204 | value); |
| 205 | } |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 206 | } |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 207 | } |
Shaohui Xie | 84900b5 | 2016-10-17 16:20:48 +0800 | [diff] [blame] | 208 | miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f, 0); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 209 | } |
| 210 | error: |
| 211 | if (ret) |
| 212 | printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac_id); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | static void qsgmii_configure_repeater(int dpmac) |
| 217 | { |
| 218 | uint8_t a = 0xf; |
| 219 | int i, j; |
| 220 | int i2c_phy_addr = 0; |
| 221 | int phy_addr = 0; |
| 222 | int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b}; |
| 223 | |
| 224 | uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7}; |
| 225 | uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84}; |
| 226 | uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7}; |
| 227 | uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84}; |
| 228 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 229 | const char *dev = "LS2080A_QDS_MDIO0"; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 230 | int ret = 0; |
| 231 | unsigned short value; |
| 232 | |
| 233 | /* Set I2c to Slot 1 */ |
| 234 | i2c_write(0x77, 0, 0, &a, 1); |
| 235 | |
| 236 | switch (dpmac) { |
| 237 | case 1: |
| 238 | case 2: |
| 239 | case 3: |
| 240 | case 4: |
| 241 | i2c_phy_addr = i2c_addr[0]; |
| 242 | phy_addr = 0; |
| 243 | break; |
| 244 | |
| 245 | case 5: |
| 246 | case 6: |
| 247 | case 7: |
| 248 | case 8: |
| 249 | i2c_phy_addr = i2c_addr[1]; |
| 250 | phy_addr = 4; |
| 251 | break; |
| 252 | |
| 253 | case 9: |
| 254 | case 10: |
| 255 | case 11: |
| 256 | case 12: |
| 257 | i2c_phy_addr = i2c_addr[2]; |
| 258 | phy_addr = 8; |
| 259 | break; |
| 260 | |
| 261 | case 13: |
| 262 | case 14: |
| 263 | case 15: |
| 264 | case 16: |
| 265 | i2c_phy_addr = i2c_addr[3]; |
| 266 | phy_addr = 0xc; |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | /* Check the PHY status */ |
| 271 | ret = miiphy_set_current_dev(dev); |
| 272 | ret = miiphy_write(dev, phy_addr, 0x1f, 3); |
| 273 | mdelay(10); |
| 274 | ret = miiphy_read(dev, phy_addr, 0x11, &value); |
| 275 | mdelay(10); |
| 276 | ret = miiphy_read(dev, phy_addr, 0x11, &value); |
| 277 | mdelay(10); |
| 278 | if ((value & 0xf) == 0xf) { |
| 279 | printf("DPMAC %d :PHY is ..... Configured\n", dpmac); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | for (i = 0; i < 4; i++) { |
| 284 | for (j = 0; j < 4; j++) { |
| 285 | a = 0x18; |
| 286 | i2c_write(i2c_phy_addr, 6, 1, &a, 1); |
| 287 | a = 0x38; |
| 288 | i2c_write(i2c_phy_addr, 4, 1, &a, 1); |
| 289 | a = 0x4; |
| 290 | i2c_write(i2c_phy_addr, 8, 1, &a, 1); |
| 291 | |
| 292 | i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1); |
| 293 | i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1); |
| 294 | |
| 295 | i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1); |
| 296 | i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1); |
| 297 | |
| 298 | a = 0x14; |
| 299 | i2c_write(i2c_phy_addr, 0x23, 1, &a, 1); |
| 300 | a = 0xb5; |
| 301 | i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1); |
| 302 | a = 0x20; |
| 303 | i2c_write(i2c_phy_addr, 4, 1, &a, 1); |
| 304 | mdelay(100); |
| 305 | ret = miiphy_read(dev, phy_addr, 0x11, &value); |
| 306 | if (ret > 0) |
| 307 | goto error; |
| 308 | mdelay(1); |
| 309 | ret = miiphy_read(dev, phy_addr, 0x11, &value); |
| 310 | if (ret > 0) |
| 311 | goto error; |
| 312 | mdelay(10); |
| 313 | if ((value & 0xf) == 0xf) { |
| 314 | printf("DPMAC %d :PHY is ..... Configured\n", |
| 315 | dpmac); |
| 316 | return; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | error: |
| 321 | printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac); |
| 322 | return; |
| 323 | } |
| 324 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 325 | static const char *ls2080a_qds_mdio_name_for_muxval(u8 muxval) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 326 | { |
| 327 | return mdio_names[muxval]; |
| 328 | } |
| 329 | |
| 330 | struct mii_dev *mii_dev_for_muxval(u8 muxval) |
| 331 | { |
| 332 | struct mii_dev *bus; |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 333 | const char *name = ls2080a_qds_mdio_name_for_muxval(muxval); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 334 | |
| 335 | if (!name) { |
| 336 | printf("No bus for muxval %x\n", muxval); |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | bus = miiphy_get_dev_by_name(name); |
| 341 | |
| 342 | if (!bus) { |
| 343 | printf("No bus by name %s\n", name); |
| 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | return bus; |
| 348 | } |
| 349 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 350 | static void ls2080a_qds_enable_SFP_TX(u8 muxval) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 351 | { |
| 352 | u8 brdcfg9; |
| 353 | |
| 354 | brdcfg9 = QIXIS_READ(brdcfg[9]); |
| 355 | brdcfg9 &= ~BRDCFG9_SFPTX_MASK; |
| 356 | brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT); |
| 357 | QIXIS_WRITE(brdcfg[9], brdcfg9); |
| 358 | } |
| 359 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 360 | static void ls2080a_qds_mux_mdio(u8 muxval) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 361 | { |
| 362 | u8 brdcfg4; |
| 363 | |
| 364 | if (muxval <= 5) { |
| 365 | brdcfg4 = QIXIS_READ(brdcfg[4]); |
| 366 | brdcfg4 &= ~BRDCFG4_EMISEL_MASK; |
| 367 | brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT); |
| 368 | QIXIS_WRITE(brdcfg[4], brdcfg4); |
| 369 | } |
| 370 | } |
| 371 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 372 | static int ls2080a_qds_mdio_read(struct mii_dev *bus, int addr, |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 373 | int devad, int regnum) |
| 374 | { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 375 | struct ls2080a_qds_mdio *priv = bus->priv; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 376 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 377 | ls2080a_qds_mux_mdio(priv->muxval); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 378 | |
| 379 | return priv->realbus->read(priv->realbus, addr, devad, regnum); |
| 380 | } |
| 381 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 382 | static int ls2080a_qds_mdio_write(struct mii_dev *bus, int addr, int devad, |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 383 | int regnum, u16 value) |
| 384 | { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 385 | struct ls2080a_qds_mdio *priv = bus->priv; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 386 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 387 | ls2080a_qds_mux_mdio(priv->muxval); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 388 | |
| 389 | return priv->realbus->write(priv->realbus, addr, devad, regnum, value); |
| 390 | } |
| 391 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 392 | static int ls2080a_qds_mdio_reset(struct mii_dev *bus) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 393 | { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 394 | struct ls2080a_qds_mdio *priv = bus->priv; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 395 | |
| 396 | return priv->realbus->reset(priv->realbus); |
| 397 | } |
| 398 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 399 | static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 400 | { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 401 | struct ls2080a_qds_mdio *pmdio; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 402 | struct mii_dev *bus = mdio_alloc(); |
| 403 | |
| 404 | if (!bus) { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 405 | printf("Failed to allocate ls2080a_qds MDIO bus\n"); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 406 | return -1; |
| 407 | } |
| 408 | |
| 409 | pmdio = malloc(sizeof(*pmdio)); |
| 410 | if (!pmdio) { |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 411 | printf("Failed to allocate ls2080a_qds private data\n"); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 412 | free(bus); |
| 413 | return -1; |
| 414 | } |
| 415 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 416 | bus->read = ls2080a_qds_mdio_read; |
| 417 | bus->write = ls2080a_qds_mdio_write; |
| 418 | bus->reset = ls2080a_qds_mdio_reset; |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 419 | strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval)); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 420 | |
| 421 | pmdio->realbus = miiphy_get_dev_by_name(realbusname); |
| 422 | |
| 423 | if (!pmdio->realbus) { |
| 424 | printf("No bus with name %s\n", realbusname); |
| 425 | free(bus); |
| 426 | free(pmdio); |
| 427 | return -1; |
| 428 | } |
| 429 | |
| 430 | pmdio->muxval = muxval; |
| 431 | bus->priv = pmdio; |
| 432 | |
| 433 | return mdio_register(bus); |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * Initialize the dpmac_info array. |
| 438 | * |
| 439 | */ |
| 440 | static void initialize_dpmac_to_slot(void) |
| 441 | { |
| 442 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 443 | int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 444 | FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK) |
| 445 | >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT; |
| 446 | int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 447 | FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK) |
| 448 | >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT; |
| 449 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 450 | char *env_hwconfig; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 451 | env_hwconfig = env_get("hwconfig"); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 452 | |
| 453 | switch (serdes1_prtcl) { |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 454 | case 0x07: |
| 455 | case 0x09: |
| 456 | case 0x33: |
| 457 | printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n", |
| 458 | serdes1_prtcl); |
| 459 | lane_to_slot_fsm1[0] = EMI1_SLOT1; |
| 460 | lane_to_slot_fsm1[1] = EMI1_SLOT1; |
| 461 | lane_to_slot_fsm1[2] = EMI1_SLOT1; |
| 462 | lane_to_slot_fsm1[3] = EMI1_SLOT1; |
| 463 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 464 | lane_to_slot_fsm1[4] = EMI1_SLOT1; |
| 465 | lane_to_slot_fsm1[5] = EMI1_SLOT1; |
| 466 | lane_to_slot_fsm1[6] = EMI1_SLOT1; |
| 467 | lane_to_slot_fsm1[7] = EMI1_SLOT1; |
| 468 | } else { |
| 469 | lane_to_slot_fsm1[4] = EMI1_SLOT2; |
| 470 | lane_to_slot_fsm1[5] = EMI1_SLOT2; |
| 471 | lane_to_slot_fsm1[6] = EMI1_SLOT2; |
| 472 | lane_to_slot_fsm1[7] = EMI1_SLOT2; |
| 473 | } |
| 474 | break; |
| 475 | |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 476 | case 0x39: |
| 477 | printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n", |
| 478 | serdes1_prtcl); |
| 479 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 480 | lane_to_slot_fsm1[0] = EMI1_SLOT3; |
| 481 | lane_to_slot_fsm1[1] = EMI1_SLOT3; |
| 482 | lane_to_slot_fsm1[2] = EMI1_SLOT3; |
| 483 | lane_to_slot_fsm1[3] = EMI_NONE; |
| 484 | } else { |
| 485 | lane_to_slot_fsm1[0] = EMI_NONE; |
| 486 | lane_to_slot_fsm1[1] = EMI_NONE; |
| 487 | lane_to_slot_fsm1[2] = EMI_NONE; |
| 488 | lane_to_slot_fsm1[3] = EMI_NONE; |
| 489 | } |
| 490 | lane_to_slot_fsm1[4] = EMI1_SLOT3; |
| 491 | lane_to_slot_fsm1[5] = EMI1_SLOT3; |
| 492 | lane_to_slot_fsm1[6] = EMI1_SLOT3; |
| 493 | lane_to_slot_fsm1[7] = EMI_NONE; |
| 494 | break; |
| 495 | |
| 496 | case 0x4D: |
| 497 | printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n", |
| 498 | serdes1_prtcl); |
| 499 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 500 | lane_to_slot_fsm1[0] = EMI1_SLOT3; |
| 501 | lane_to_slot_fsm1[1] = EMI1_SLOT3; |
| 502 | lane_to_slot_fsm1[2] = EMI_NONE; |
| 503 | lane_to_slot_fsm1[3] = EMI_NONE; |
| 504 | } else { |
| 505 | lane_to_slot_fsm1[0] = EMI_NONE; |
| 506 | lane_to_slot_fsm1[1] = EMI_NONE; |
| 507 | lane_to_slot_fsm1[2] = EMI_NONE; |
| 508 | lane_to_slot_fsm1[3] = EMI_NONE; |
| 509 | } |
| 510 | lane_to_slot_fsm1[4] = EMI1_SLOT3; |
| 511 | lane_to_slot_fsm1[5] = EMI1_SLOT3; |
| 512 | lane_to_slot_fsm1[6] = EMI_NONE; |
| 513 | lane_to_slot_fsm1[7] = EMI_NONE; |
| 514 | break; |
| 515 | |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 516 | case 0x2A: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 517 | case 0x4B: |
| 518 | case 0x4C: |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 519 | printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n", |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 520 | serdes1_prtcl); |
| 521 | break; |
| 522 | default: |
Prabhakar Kushwaha | c5aa4ff | 2015-11-04 12:25:55 +0530 | [diff] [blame] | 523 | printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n", |
| 524 | __func__, serdes1_prtcl); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 525 | break; |
| 526 | } |
| 527 | |
| 528 | switch (serdes2_prtcl) { |
| 529 | case 0x07: |
| 530 | case 0x08: |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 531 | case 0x09: |
Prabhakar Kushwaha | 2a6e5dc | 2015-05-28 14:53:57 +0530 | [diff] [blame] | 532 | case 0x49: |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 533 | printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n", |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 534 | serdes2_prtcl); |
| 535 | lane_to_slot_fsm2[0] = EMI1_SLOT4; |
| 536 | lane_to_slot_fsm2[1] = EMI1_SLOT4; |
| 537 | lane_to_slot_fsm2[2] = EMI1_SLOT4; |
| 538 | lane_to_slot_fsm2[3] = EMI1_SLOT4; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 539 | |
| 540 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 541 | lane_to_slot_fsm2[4] = EMI1_SLOT4; |
| 542 | lane_to_slot_fsm2[5] = EMI1_SLOT4; |
| 543 | lane_to_slot_fsm2[6] = EMI1_SLOT4; |
| 544 | lane_to_slot_fsm2[7] = EMI1_SLOT4; |
| 545 | } else { |
| 546 | /* No MDIO physical connection */ |
| 547 | lane_to_slot_fsm2[4] = EMI1_SLOT6; |
| 548 | lane_to_slot_fsm2[5] = EMI1_SLOT6; |
| 549 | lane_to_slot_fsm2[6] = EMI1_SLOT6; |
| 550 | lane_to_slot_fsm2[7] = EMI1_SLOT6; |
| 551 | } |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case 0x47: |
| 555 | printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n", |
| 556 | serdes2_prtcl); |
| 557 | lane_to_slot_fsm2[0] = EMI_NONE; |
| 558 | lane_to_slot_fsm2[1] = EMI1_SLOT5; |
| 559 | lane_to_slot_fsm2[2] = EMI1_SLOT5; |
| 560 | lane_to_slot_fsm2[3] = EMI1_SLOT5; |
| 561 | |
| 562 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 563 | lane_to_slot_fsm2[4] = EMI_NONE; |
| 564 | lane_to_slot_fsm2[5] = EMI1_SLOT5; |
| 565 | lane_to_slot_fsm2[6] = EMI1_SLOT5; |
| 566 | lane_to_slot_fsm2[7] = EMI1_SLOT5; |
| 567 | } |
| 568 | break; |
| 569 | |
| 570 | case 0x57: |
| 571 | printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n", |
| 572 | serdes2_prtcl); |
| 573 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 574 | lane_to_slot_fsm2[0] = EMI_NONE; |
| 575 | lane_to_slot_fsm2[1] = EMI_NONE; |
| 576 | lane_to_slot_fsm2[2] = EMI_NONE; |
| 577 | lane_to_slot_fsm2[3] = EMI_NONE; |
| 578 | } |
| 579 | lane_to_slot_fsm2[4] = EMI_NONE; |
| 580 | lane_to_slot_fsm2[5] = EMI_NONE; |
| 581 | lane_to_slot_fsm2[6] = EMI1_SLOT5; |
| 582 | lane_to_slot_fsm2[7] = EMI1_SLOT5; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 583 | break; |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 584 | |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 585 | default: |
Prabhakar Kushwaha | c5aa4ff | 2015-11-04 12:25:55 +0530 | [diff] [blame] | 586 | printf(" %s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n", |
| 587 | __func__ , serdes2_prtcl); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 588 | break; |
| 589 | } |
| 590 | } |
| 591 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 592 | void ls2080a_handle_phy_interface_sgmii(int dpmac_id) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 593 | { |
| 594 | int lane, slot; |
| 595 | struct mii_dev *bus; |
| 596 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 597 | int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 598 | FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK) |
| 599 | >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT; |
| 600 | int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 601 | FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK) |
| 602 | >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT; |
| 603 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 604 | int *riser_phy_addr; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 605 | char *env_hwconfig = env_get("hwconfig"); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 606 | |
| 607 | if (hwconfig_f("xqsgmii", env_hwconfig)) |
| 608 | riser_phy_addr = &xqsgii_riser_phy_addr[0]; |
| 609 | else |
| 610 | riser_phy_addr = &sgmii_riser_phy_addr[0]; |
| 611 | |
| 612 | if (dpmac_id > WRIOP1_DPMAC9) |
| 613 | goto serdes2; |
| 614 | |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 615 | switch (serdes1_prtcl) { |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 616 | case 0x07: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 617 | case 0x39: |
| 618 | case 0x4D: |
| 619 | lane = serdes_get_first_lane(FSL_SRDS_1, SGMII1 + dpmac_id - 1); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 620 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 621 | slot = lane_to_slot_fsm1[lane]; |
| 622 | |
| 623 | switch (++slot) { |
| 624 | case 1: |
| 625 | /* Slot housing a SGMII riser card? */ |
| 626 | wriop_set_phy_address(dpmac_id, |
| 627 | riser_phy_addr[dpmac_id - 1]); |
| 628 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT1; |
| 629 | bus = mii_dev_for_muxval(EMI1_SLOT1); |
| 630 | wriop_set_mdio(dpmac_id, bus); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 631 | break; |
| 632 | case 2: |
| 633 | /* Slot housing a SGMII riser card? */ |
| 634 | wriop_set_phy_address(dpmac_id, |
| 635 | riser_phy_addr[dpmac_id - 1]); |
| 636 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT2; |
| 637 | bus = mii_dev_for_muxval(EMI1_SLOT2); |
| 638 | wriop_set_mdio(dpmac_id, bus); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 639 | break; |
| 640 | case 3: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 641 | if (slot == EMI_NONE) |
| 642 | return; |
| 643 | if (serdes1_prtcl == 0x39) { |
| 644 | wriop_set_phy_address(dpmac_id, |
| 645 | riser_phy_addr[dpmac_id - 2]); |
| 646 | if (dpmac_id >= 6 && hwconfig_f("xqsgmii", |
| 647 | env_hwconfig)) |
| 648 | wriop_set_phy_address(dpmac_id, |
| 649 | riser_phy_addr[dpmac_id - 3]); |
| 650 | } else { |
| 651 | wriop_set_phy_address(dpmac_id, |
| 652 | riser_phy_addr[dpmac_id - 2]); |
| 653 | if (dpmac_id >= 7 && hwconfig_f("xqsgmii", |
| 654 | env_hwconfig)) |
| 655 | wriop_set_phy_address(dpmac_id, |
| 656 | riser_phy_addr[dpmac_id - 3]); |
| 657 | } |
| 658 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT3; |
| 659 | bus = mii_dev_for_muxval(EMI1_SLOT3); |
| 660 | wriop_set_mdio(dpmac_id, bus); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 661 | break; |
| 662 | case 4: |
| 663 | break; |
| 664 | case 5: |
| 665 | break; |
| 666 | case 6: |
| 667 | break; |
| 668 | } |
| 669 | break; |
| 670 | default: |
Prabhakar Kushwaha | c5aa4ff | 2015-11-04 12:25:55 +0530 | [diff] [blame] | 671 | printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n", |
| 672 | __func__ , serdes1_prtcl); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 673 | break; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 676 | serdes2: |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 677 | switch (serdes2_prtcl) { |
| 678 | case 0x07: |
| 679 | case 0x08: |
Prabhakar Kushwaha | 2a6e5dc | 2015-05-28 14:53:57 +0530 | [diff] [blame] | 680 | case 0x49: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 681 | case 0x47: |
| 682 | case 0x57: |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 683 | lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 + |
| 684 | (dpmac_id - 9)); |
| 685 | slot = lane_to_slot_fsm2[lane]; |
| 686 | |
| 687 | switch (++slot) { |
| 688 | case 1: |
| 689 | break; |
| 690 | case 3: |
| 691 | break; |
| 692 | case 4: |
| 693 | /* Slot housing a SGMII riser card? */ |
| 694 | wriop_set_phy_address(dpmac_id, |
| 695 | riser_phy_addr[dpmac_id - 9]); |
| 696 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT4; |
| 697 | bus = mii_dev_for_muxval(EMI1_SLOT4); |
| 698 | wriop_set_mdio(dpmac_id, bus); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 699 | break; |
| 700 | case 5: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 701 | if (slot == EMI_NONE) |
| 702 | return; |
| 703 | if (serdes2_prtcl == 0x47) { |
| 704 | wriop_set_phy_address(dpmac_id, |
| 705 | riser_phy_addr[dpmac_id - 10]); |
| 706 | if (dpmac_id >= 14 && hwconfig_f("xqsgmii", |
| 707 | env_hwconfig)) |
| 708 | wriop_set_phy_address(dpmac_id, |
| 709 | riser_phy_addr[dpmac_id - 11]); |
| 710 | } else { |
| 711 | wriop_set_phy_address(dpmac_id, |
| 712 | riser_phy_addr[dpmac_id - 11]); |
| 713 | } |
| 714 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT5; |
| 715 | bus = mii_dev_for_muxval(EMI1_SLOT5); |
| 716 | wriop_set_mdio(dpmac_id, bus); |
| 717 | break; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 718 | case 6: |
| 719 | /* Slot housing a SGMII riser card? */ |
| 720 | wriop_set_phy_address(dpmac_id, |
| 721 | riser_phy_addr[dpmac_id - 13]); |
| 722 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT6; |
| 723 | bus = mii_dev_for_muxval(EMI1_SLOT6); |
| 724 | wriop_set_mdio(dpmac_id, bus); |
| 725 | break; |
| 726 | } |
| 727 | break; |
| 728 | default: |
Prabhakar Kushwaha | c5aa4ff | 2015-11-04 12:25:55 +0530 | [diff] [blame] | 729 | printf("%s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n", |
| 730 | __func__, serdes2_prtcl); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 731 | break; |
| 732 | } |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 733 | } |
| 734 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 735 | void ls2080a_handle_phy_interface_qsgmii(int dpmac_id) |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 736 | { |
| 737 | int lane = 0, slot; |
| 738 | struct mii_dev *bus; |
| 739 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 740 | int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 741 | FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK) |
| 742 | >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT; |
| 743 | |
| 744 | switch (serdes1_prtcl) { |
| 745 | case 0x33: |
| 746 | switch (dpmac_id) { |
| 747 | case 1: |
| 748 | case 2: |
| 749 | case 3: |
| 750 | case 4: |
| 751 | lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_A); |
| 752 | break; |
| 753 | case 5: |
| 754 | case 6: |
| 755 | case 7: |
| 756 | case 8: |
| 757 | lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_B); |
| 758 | break; |
| 759 | case 9: |
| 760 | case 10: |
| 761 | case 11: |
| 762 | case 12: |
| 763 | lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_C); |
| 764 | break; |
| 765 | case 13: |
| 766 | case 14: |
| 767 | case 15: |
| 768 | case 16: |
| 769 | lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_D); |
| 770 | break; |
| 771 | } |
| 772 | |
| 773 | slot = lane_to_slot_fsm1[lane]; |
| 774 | |
| 775 | switch (++slot) { |
| 776 | case 1: |
| 777 | /* Slot housing a QSGMII riser card? */ |
| 778 | wriop_set_phy_address(dpmac_id, dpmac_id - 1); |
| 779 | dpmac_info[dpmac_id].board_mux = EMI1_SLOT1; |
| 780 | bus = mii_dev_for_muxval(EMI1_SLOT1); |
| 781 | wriop_set_mdio(dpmac_id, bus); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 782 | break; |
| 783 | case 3: |
| 784 | break; |
| 785 | case 4: |
| 786 | break; |
| 787 | case 5: |
| 788 | break; |
| 789 | case 6: |
| 790 | break; |
| 791 | } |
| 792 | break; |
| 793 | default: |
| 794 | printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n", |
| 795 | serdes1_prtcl); |
| 796 | break; |
| 797 | } |
| 798 | |
| 799 | qsgmii_configure_repeater(dpmac_id); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 800 | } |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 801 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 802 | void ls2080a_handle_phy_interface_xsgmii(int i) |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 803 | { |
| 804 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 805 | int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 806 | FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK) |
| 807 | >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT; |
| 808 | |
| 809 | switch (serdes1_prtcl) { |
| 810 | case 0x2A: |
Priyanka Jain | e2da623 | 2016-11-03 17:50:51 +0530 | [diff] [blame] | 811 | case 0x4B: |
| 812 | case 0x4C: |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 813 | /* |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 814 | * XFI does not need a PHY to work, but to avoid U-Boot use |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 815 | * default PHY address which is zero to a MAC when it found |
| 816 | * a MAC has no PHY address, we give a PHY address to XFI |
| 817 | * MAC, and should not use a real XAUI PHY address, since |
| 818 | * MDIO can access it successfully, and then MDIO thinks |
| 819 | * the XAUI card is used for the XFI MAC, which will cause |
| 820 | * error. |
| 821 | */ |
| 822 | wriop_set_phy_address(i, i + 4); |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 823 | ls2080a_qds_enable_SFP_TX(SFP_TX); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 824 | |
| 825 | break; |
| 826 | default: |
| 827 | printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n", |
| 828 | serdes1_prtcl); |
| 829 | break; |
| 830 | } |
| 831 | } |
| 832 | #endif |
| 833 | |
| 834 | int board_eth_init(bd_t *bis) |
| 835 | { |
| 836 | int error; |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 837 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 838 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 839 | int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 840 | FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK) |
| 841 | >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT; |
| 842 | int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) & |
| 843 | FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK) |
| 844 | >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT; |
| 845 | |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 846 | struct memac_mdio_info *memac_mdio0_info; |
| 847 | struct memac_mdio_info *memac_mdio1_info; |
| 848 | unsigned int i; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 849 | char *env_hwconfig; |
| 850 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 851 | env_hwconfig = env_get("hwconfig"); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 852 | |
| 853 | initialize_dpmac_to_slot(); |
| 854 | |
| 855 | memac_mdio0_info = (struct memac_mdio_info *)malloc( |
| 856 | sizeof(struct memac_mdio_info)); |
| 857 | memac_mdio0_info->regs = |
| 858 | (struct memac_mdio_controller *) |
| 859 | CONFIG_SYS_FSL_WRIOP1_MDIO1; |
| 860 | memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME; |
| 861 | |
| 862 | /* Register the real MDIO1 bus */ |
| 863 | fm_memac_mdio_init(bis, memac_mdio0_info); |
| 864 | |
| 865 | memac_mdio1_info = (struct memac_mdio_info *)malloc( |
| 866 | sizeof(struct memac_mdio_info)); |
| 867 | memac_mdio1_info->regs = |
| 868 | (struct memac_mdio_controller *) |
| 869 | CONFIG_SYS_FSL_WRIOP1_MDIO2; |
| 870 | memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME; |
| 871 | |
| 872 | /* Register the real MDIO2 bus */ |
| 873 | fm_memac_mdio_init(bis, memac_mdio1_info); |
| 874 | |
| 875 | /* Register the muxing front-ends to the MDIO buses */ |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 876 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1); |
| 877 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2); |
| 878 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3); |
| 879 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4); |
| 880 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5); |
| 881 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 882 | |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 883 | ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 884 | |
| 885 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 886 | switch (wriop_get_enet_if(i)) { |
| 887 | case PHY_INTERFACE_MODE_QSGMII: |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 888 | ls2080a_handle_phy_interface_qsgmii(i); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 889 | break; |
| 890 | case PHY_INTERFACE_MODE_SGMII: |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 891 | ls2080a_handle_phy_interface_sgmii(i); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 892 | break; |
| 893 | case PHY_INTERFACE_MODE_XGMII: |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 894 | ls2080a_handle_phy_interface_xsgmii(i); |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 895 | break; |
| 896 | default: |
| 897 | break; |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 898 | |
| 899 | if (i == 16) |
| 900 | i = NUM_WRIOP_PORTS; |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
| 904 | error = cpu_eth_init(bis); |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 905 | |
| 906 | if (hwconfig_f("xqsgmii", env_hwconfig)) { |
| 907 | if (serdes1_prtcl == 0x7) |
| 908 | sgmii_configure_repeater(1); |
| 909 | if (serdes2_prtcl == 0x7 || serdes2_prtcl == 0x8 || |
| 910 | serdes2_prtcl == 0x49) |
| 911 | sgmii_configure_repeater(2); |
| 912 | } |
Prabhakar Kushwaha | c158fad | 2015-03-20 19:28:26 -0700 | [diff] [blame] | 913 | #endif |
| 914 | error = pci_eth_init(bis); |
| 915 | return error; |
| 916 | } |
Prabhakar Kushwaha | 35f93f6 | 2015-08-07 18:01:51 +0530 | [diff] [blame] | 917 | |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 918 | #if defined(CONFIG_RESET_PHY_R) |
| 919 | void reset_phy(void) |
| 920 | { |
| 921 | mc_env_boot(); |
| 922 | } |
| 923 | #endif /* CONFIG_RESET_PHY_R */ |