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