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