xref: /openbmc/u-boot/drivers/net/phy/generic_10g.c (revision 8ee59472)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Generic PHY Management code
4  *
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;
24 	u32 mmd_mask = phydev->mmds & MDIO_DEVS_LINK;
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 
32 	/*
33 	 * Go through all the link-reporting devices, and make sure
34 	 * they're all up and happy
35 	 */
36 	for (devad = 0; mmd_mask; devad++, mmd_mask = mmd_mask >> 1) {
37 		if (!(mmd_mask & 1))
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 };
94