Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Generic PHY Management code |
| 4 | * |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 5 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 6 | * author Andy Fleming |
| 7 | * |
| 8 | * Based loosely off of Linux's PHY Lib |
| 9 | */ |
| 10 | |
| 11 | #include <config.h> |
| 12 | #include <common.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <phy.h> |
| 15 | |
| 16 | int gen10g_shutdown(struct phy_device *phydev) |
| 17 | { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | int gen10g_startup(struct phy_device *phydev) |
| 22 | { |
| 23 | int devad, reg; |
Andy Fleming | ee8fa20 | 2011-05-18 13:44:19 +0000 | [diff] [blame] | 24 | u32 mmd_mask = phydev->mmds & MDIO_DEVS_LINK; |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 25 | |
| 26 | phydev->link = 1; |
| 27 | |
| 28 | /* For now just lie and say it's 10G all the time */ |
| 29 | phydev->speed = SPEED_10000; |
| 30 | phydev->duplex = DUPLEX_FULL; |
| 31 | |
Andy Fleming | ee8fa20 | 2011-05-18 13:44:19 +0000 | [diff] [blame] | 32 | /* |
| 33 | * Go through all the link-reporting devices, and make sure |
| 34 | * they're all up and happy |
| 35 | */ |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 36 | for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) { |
Andy Fleming | ee8fa20 | 2011-05-18 13:44:19 +0000 | [diff] [blame] | 37 | if (!(mmd_mask & 1)) |
Andy Fleming | 5f18471 | 2011-04-08 02:10:27 -0500 | [diff] [blame] | 38 | continue; |
| 39 | |
| 40 | /* Read twice because link state is latched and a |
| 41 | * read moves the current state into the register */ |
| 42 | phy_read(phydev, devad, MDIO_STAT1); |
| 43 | reg = phy_read(phydev, devad, MDIO_STAT1); |
| 44 | if (reg < 0 || !(reg & MDIO_STAT1_LSTATUS)) |
| 45 | phydev->link = 0; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int gen10g_discover_mmds(struct phy_device *phydev) |
| 52 | { |
| 53 | int mmd, stat2, devs1, devs2; |
| 54 | |
| 55 | /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY |
| 56 | * XS or DTE XS; give up if none is present. */ |
| 57 | for (mmd = 1; mmd <= 5; mmd++) { |
| 58 | /* Is this MMD present? */ |
| 59 | stat2 = phy_read(phydev, mmd, MDIO_STAT2); |
| 60 | if (stat2 < 0 || |
| 61 | (stat2 & MDIO_STAT2_DEVPRST) != MDIO_STAT2_DEVPRST_VAL) |
| 62 | continue; |
| 63 | |
| 64 | /* It should tell us about all the other MMDs */ |
| 65 | devs1 = phy_read(phydev, mmd, MDIO_DEVS1); |
| 66 | devs2 = phy_read(phydev, mmd, MDIO_DEVS2); |
| 67 | if (devs1 < 0 || devs2 < 0) |
| 68 | continue; |
| 69 | |
| 70 | phydev->mmds = devs1 | (devs2 << 16); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int gen10g_config(struct phy_device *phydev) |
| 78 | { |
| 79 | /* For now, assume 10000baseT. Fill in later */ |
| 80 | phydev->supported = phydev->advertising = SUPPORTED_10000baseT_Full; |
| 81 | |
| 82 | return gen10g_discover_mmds(phydev); |
| 83 | } |
| 84 | |
| 85 | struct phy_driver gen10g_driver = { |
| 86 | .uid = 0xffffffff, |
| 87 | .mask = 0xffffffff, |
| 88 | .name = "Generic 10G PHY", |
| 89 | .features = 0, |
| 90 | .config = gen10g_config, |
| 91 | .startup = gen10g_startup, |
| 92 | .shutdown = gen10g_shutdown, |
| 93 | }; |